Phone Number Regex Patterns — Test US and International Validation Online
Table of Contents
Phone number validation is notoriously tricky because humans enter phone numbers in dozens of different formats: with dashes, dots, spaces, parentheses, country codes, or no formatting at all. A regex that accepts only (123) 456-7890 will reject 123-456-7890 and 1234567890 — all of which represent the same valid US number.
The free regex tester at WildandFree Tools lets you paste any phone pattern and see immediately which formats it catches and which it misses. This guide covers the main pattern tiers and helps you pick the right level of strictness for your use case.
Why Phone Number Regex Is Harder Than It Looks
Three factors make phone validation complex:
1. Format variability. A US phone number can legitimately appear as:
1234567890(raw digits)123-456-7890(dash-separated)(123) 456-7890(standard US)123.456.7890(dot-separated)+1 123 456 7890(E.164 with country code)+11234567890(E.164 compact)
2. Country code complexity. International numbers vary from 7 to 15 digits (E.164 standard). Country codes range from 1 to 3 digits. A pattern that works for US numbers will fail for UK (+44), Germany (+49), or India (+91) numbers with different digit counts.
3. Extension handling. Business numbers often include extensions: (123) 456-7890 ext. 234 or 123-456-7890 x234. Most simple patterns reject these.
The right approach depends on your audience: US-only app, global app, or internal business system with extensions.
US Phone Number Patterns — From Strict to Flexible
Test each of these in the browser tester against the format list above to see exactly what each accepts:
Strict — one format only:
^\(\d{3}\) \d{3}-\d{4}$
Matches only (123) 456-7890. Good for systems where you control data entry and want normalized storage.
Common formats — most user input:
^[\+]?[1]?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
Accepts dashes, dots, spaces, optional parentheses, optional country code. Test it — you'll see it accepts all six formats in the list above. Rejects inputs with fewer than 10 digits or letters mixed in.
Permissive — just 10 digits:
^\D*(\d\D*){10}$
Extracts any string that contains exactly 10 digits, regardless of separator. Then strip non-digits in your code: phone.replace(/\D/g, ''). Use this tier when users are typing freeform text and you'll normalize it server-side.
International Phone Regex — E.164 and Flexible Matching
E.164 strict: ^\+[1-9]\d{6,14}$
E.164 is the international standard: + followed by country code and number, 7–15 digits total. Test it against:
+12125551234— matches (US)+441234567890— matches (UK)+919876543210— matches (India)+1-212-555-1234— no match (dashes not allowed in strict E.164)
E.164 flexible (allows separators):
^\+[1-9][\d\s\-\.]{6,14}\d$
Accepts international numbers with spaces, dashes, or dots as separators. The trailing \d ensures the number ends with a digit, not a separator.
Global catch-all:
^\+?[\d\s\-\.\(\)]{7,20}$
Accepts any string of 7–20 characters containing digits and common separators. Normalize by stripping non-digits server-side. Use when supporting many international formats without knowing them all in advance.
Sell Custom Apparel — We Handle Printing & Free ShippingExtension Handling in Phone Patterns
To accept extensions, append an optional group to any base pattern:
Extension suffix: (\s?(x|ext|extension)\.?\s?\d{1,6})?$
Full example with common US format plus extension:
^[\+]?[1]?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}(\s?(x|ext|extension)\.?\s?\d{1,6})?$
Test in the browser tester with the i flag to catch uppercase "EXT" and "Extension" variations. Sample inputs to test:
123-456-7890 x234— should match(123) 456-7890 ext. 12— should match123.456.7890 Extension 5678— should match with i flag123-456-7890 extra digits— should not match (non-extension suffix)
Extracting Phone Numbers From Text (Bulk and Log Parsing)
If you're extracting phone numbers from unstructured text — customer support tickets, log files, form submissions — use the g flag in the browser tester to find all matches in a block of text.
Pattern for extracting US numbers anywhere in text:
\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}\b
Paste a paragraph of sample text into the test input field with the g flag enabled. The tester highlights every phone number it finds. Adjust the pattern if it matches non-phone numbers (like product codes with 10 consecutive digits).
For extracting and normalizing at scale (Python, Go, JS), the workflow is:
- Use the regex to find candidate strings
- Strip all non-digit characters:
s.replace(/\D/g, '') - Validate the digit count (10 for US, 7–15 for international)
- Store in normalized E.164 format
Choosing the Right Phone Regex for Your Project
| Use case | Recommended approach |
|---|---|
| US-only form field | Common formats pattern + normalize server-side |
| International form field | E.164 flexible + normalize server-side |
| Strict data storage (US) | Strict \(\d{3}\) \d{3}-\d{4} after normalizing |
| Extracting from text | Permissive extraction + digit count validation |
| API input validation | E.164 strict — require callers to send normalized format |
| Business system with extensions | Common US pattern + optional extension suffix |
The safest server-side approach: accept any reasonable format with a permissive regex, then normalize by stripping non-digits, then store the normalized 10 or 11-digit version. This decouples user experience (any format) from data integrity (consistent storage).
Try It Free — No Signup Required
Runs 100% in your browser. No data is collected, stored, or sent anywhere.
Open Free Regex TesterFrequently Asked Questions
Should I validate phone numbers with regex or a library?
Library for production systems. The libphonenumber library (from Google, available for JavaScript, Python, Java, and more) handles country-specific rules, validates area codes, and formats numbers correctly. Regex is appropriate for format-level checks — catching "abc" instead of digits — but can't validate whether a number is actually dialable.
Why does my phone regex accept 10-digit product codes?
A 10-digit sequence is a 10-digit sequence — regex can't distinguish a phone number from a product code by digits alone. Add context anchors: if the number appears after a "Phone:" label, search for that label followed by the digit pattern. Or validate by context in your application logic rather than with regex alone.
How do I test my phone regex against a list of real phone numbers?
Paste all your test numbers into the browser tester's test input field, one per line. Enable the g (global) and m (multiline) flags. The tester will highlight every match. Check that all valid numbers are highlighted and no invalid strings are highlighted.

