What Regex Should You Use for Phone Numbers? Patterns for US and International Formats
Short answer: choose the pattern that matches the format you actually store. Use a North American pattern for common US input, a digits-only pattern for normalized local numbers, a plus-prefixed pattern for formatted international numbers, and the E.164 pattern when your data is already normalized.
Quick answer: choose by input format
| Use case | Regex | Example |
|---|---|---|
| US numbers with common punctuation | ^(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$ | +1 (415) 555-2671 |
| US local digits only | ^[2-9]\d{2}[2-9]\d{2}\d{4}$ | 4155552671 |
| Formatted numbers with a country code | ^\+\d{1,3}(?:[\s.-]?\d{1,4}){2,6}$ | +44 20 7946 0958 |
| E.164 normalized numbers | ^\+[1-9]\d{1,14}$ | +14155552671 |
These are format and shape checks. They do not prove that a number is assigned, reachable, or valid under every rule in a particular country.
US phone number regex
For typical US numbers, this pattern accepts an optional country code, an optional area-code pair of parentheses, and common spaces, dots, or hyphens:
^(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$ What each part does
^and$require the whole input to match.(?:\+?1[\s.-]?)?allows an optional1or+1prefix.(?:\([2-9]\d{2}\)|[2-9]\d{2})accepts either(415)or415and avoids an area code beginning with 0 or 1.[\s.-]?permits one common separator between number groups.[2-9]\d{2}applies the same practical first-digit rule to the central-office code.
This is intentionally tolerant of presentation formatting. If your application requires one exact style, remove the optional separator branches and validate the normalized value instead.
US local numbers in normalized storage
If your database stores a US number as exactly ten digits, use:
^[2-9]\d{2}[2-9]\d{2}\d{4}$ This is useful after stripping spaces, parentheses, dots, and hyphens. It rejects country-code prefixes and formatted input, so normalize first or use the formatted US pattern above.
International numbers with a country code
For a readable, plus-prefixed international format, use:
^\+\d{1,3}(?:[\s.-]?\d{1,4}){2,6}$ When to use it
This pattern checks for a leading plus sign, a one-to-three-digit country-code area, and several groups of digits separated optionally by spaces, dots, or hyphens. It can match examples such as +44 20 7946 0958, +81 3 1234 5678, and +1 415 555 2671.
It is a practical input filter, not a country-plan validator. Parentheses, extensions, trunk prefixes, and country-specific length rules need additional handling if your product supports them.
E.164 phone number regex
Use E.164 when numbers are normalized: a plus sign followed by 2 to 15 digits, with no spaces or punctuation:
^\+[1-9]\d{1,14}$ E.164 rules covered by this pattern
- The value must begin with
+. - The first digit after
+cannot be zero. - The complete number contains no more than 15 digits after the plus sign.
- Spaces, parentheses, hyphens, and extensions are not accepted.
For example, +14155552671 matches, while +1 415 555 2671 does not. Convert a display number to your canonical format before applying this check.
Input to match test table
The following examples show the expected result for the pattern named in the last column.
| Input | Matches? | Pattern | Reason |
|---|---|---|---|
415-555-2671 | Yes | US formatted | Ten-digit US presentation format |
+1 (415) 555-2671 | Yes | US formatted | Optional +1 and parentheses are allowed |
4155552671 | Yes | US local digits | Exactly ten normalized digits |
+44 20 7946 0958 | Yes | International formatted | Plus-prefixed country-code format |
+14155552671 | Yes | E.164 | Digits only and within the E.164 length limit |
+1 415 555 2671 | No | E.164 | Readable spaces are not part of E.164 |
123-555-2671 | No | US formatted | Area code cannot begin with 1 |
020 7946 0958 | No | International formatted | No leading plus and country code |
Why one global phone regex is unreliable
Phone numbers are identifiers governed by national and regional numbering plans, not one universal display format. Countries use different subscriber lengths, area-code rules, trunk prefixes, carrier prefixes, punctuation conventions, and extension formats. Even within one country, a local number may be displayed differently from its stored international form.
Use regex for a predictable shape check, then apply the right normalization and country-aware validation for your product. If the number affects account recovery, billing, or messaging, consider a dedicated phone-number library or verification step rather than treating a regex match as proof of reachability.
Test these patterns in RegexToolBox
- Open the RegexToolBox regex tester.
- Paste one of the patterns into the Generated Regex field, or describe a phone-number requirement and choose Generate Regex with AI.
- Select a language if you need a code example. The homepage currently provides JavaScript, PHP, Python, Java, and C# examples.
- Enter one phone number per line in Test Content (one per line).
- Click Validate and review the Validation Results for each input.
Common questions
What is the best regex for a US phone number?
For common formatted US input, use the US pattern in this article. If storage is normalized to ten digits, use the digits-only pattern instead.
Can the E.164 regex validate a number with spaces or hyphens?
No. E.164 is a normalized representation, so the pattern accepts only a plus sign and digits. Remove presentation separators before checking it.
Does a regex prove that a phone number is real?
No. A regex only checks whether the text has the expected shape. It cannot prove assignment, ownership, reachability, or current service.
Why is there no single regex for every country?
Numbering plans vary by country and sometimes by region, including length, prefixes, separators, and extensions. A single permissive pattern may accept invalid values, while a strict pattern may reject valid local formats.