Regex Tester & DebuggerSpecialized Version
🔍

Phone Regex Tester

Phone regex

//g
Flags:
Examples:

Phone Regex Tester

Test and validate phone number patterns with regular expressions. Handle various international formats and separators.

Phone Number Formats

FormatExamplePattern
US (plain)5551234567\d{10}
US (dashes)555-123-4567\d{3}-\d{3}-\d{4}
US (parens)(555) 123-4567\(\d{3}\) \d{3}-\d{4}
International+1-555-123-4567\+\d{1,3}-\d{3}-\d{3}-\d{4}
E.164+15551234567\+[1-9]\d{1,14}

Flexible Phone Patterns

``javascript // Accept multiple formats const flexiblePhone = /^\+?1?[-. ]?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}$/;

// Test various formats const validNumbers = [ '5551234567', '555-123-4567', '(555) 123-4567', '555.123.4567', '1-555-123-4567', '+1 555 123 4567' ];

validNumbers.every(n => flexiblePhone.test(n)); // true

// Extract and normalize function normalizePhone(phone) { const digits = phone.replace(/\D/g, ''); if (digits.length === 10) { return (${digits.slice(0,3)}) ${digits.slice(3,6)}-${digits.slice(6)}; } if (digits.length === 11 && digits[0] === '1') { return +1 (${digits.slice(1,4)}) ${digits.slice(4,7)}-${digits.slice(7)}; } return phone; }

normalizePhone('5551234567'); // "(555) 123-4567" normalizePhone('15551234567'); // "+1 (555) 123-4567" `

E.164 International Format

`javascript // E.164: +[country code][number] // Max 15 digits total, no separators const e164Pattern = /^\+[1-9]\d{1,14}$/;

// Country code patterns const countryCodes = { US: /^\+1\d{10}$/, // +1 followed by 10 digits UK: /^\+44\d{10}$/, // +44 followed by 10 digits AU: /^\+61\d{9}$/, // +61 followed by 9 digits DE: /^\+49\d{10,11}$/ // +49 followed by 10-11 digits };

// Validate with country function validatePhoneByCountry(phone, country) { const pattern = countryCodes[country]; return pattern ? pattern.test(phone) : e164Pattern.test(phone); } `

Extract Phone Numbers

`javascript // Find all phone numbers in text const phonePattern = /(?:\+?1[-. ]?)?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}/g;

const text = "Call 555-123-4567 or (800) 555-0199"; const phones = text.match(phonePattern); // Result: ["555-123-4567", "(800) 555-0199"] ``

Frequently Asked Questions

What regex should I use for phone validation?

For US numbers: ^\\+?1?[-. ]?\\(?\\d{3}\\)?[-. ]?\\d{3}[-. ]?\\d{4}$ handles most formats. For international, E.164 format ^\\+[1-9]\\d{1,14}$ is the standard. Consider using a library like libphonenumber for complex validation.

How do I handle different separators?

Use character class [-. ] to allow dash, dot, or space. Make separators optional with ?. Pattern \\d{3}[-. ]?\\d{3}[-. ]?\\d{4} matches 5551234567, 555-123-4567, 555.123.4567, and 555 123 4567.

Should I strip non-digits before validation?

Yes, for storage and comparison. Store phones as digits only (E.164 format with +). Validate the raw input for user feedback, but normalize to digits: phone.replace(/\\D/g, ""). This simplifies comparison and formatting.

Related Tools

Explore other tools you might find useful:

Related Calculators