Home >Blog

What Regex Should You Use for Phone Numbers? Patterns for US and International Formats

Published Updated

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 caseRegexExample
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 optional 1 or +1 prefix.
  • (?:\([2-9]\d{2}\)|[2-9]\d{2}) accepts either (415) or 415 and 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.

InputMatches?PatternReason
415-555-2671YesUS formattedTen-digit US presentation format
+1 (415) 555-2671YesUS formattedOptional +1 and parentheses are allowed
4155552671YesUS local digitsExactly ten normalized digits
+44 20 7946 0958YesInternational formattedPlus-prefixed country-code format
+14155552671YesE.164Digits only and within the E.164 length limit
+1 415 555 2671NoE.164Readable spaces are not part of E.164
123-555-2671NoUS formattedArea code cannot begin with 1
020 7946 0958NoInternational formattedNo 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

  1. Open the RegexToolBox regex tester.
  2. Paste one of the patterns into the Generated Regex field, or describe a phone-number requirement and choose Generate Regex with AI.
  3. Select a language if you need a code example. The homepage currently provides JavaScript, PHP, Python, Java, and C# examples.
  4. Enter one phone number per line in Test Content (one per line).
  5. 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.

FAQ

What is the best regex for a US phone number?
Use the formatted US pattern for common punctuation and an optional country code, or use the digits-only pattern when storage is normalized to ten digits.
Can the E.164 regex validate a number with spaces or hyphens?
No. E.164 is normalized, so its regex accepts only a plus sign and digits; remove presentation separators first.
Does a regex prove that a phone number is real?
No. A regex checks text shape only and cannot prove assignment, ownership, reachability, or current service.
Why is there no single regex for every country?
National numbering plans differ in length, prefixes, separators, and extensions, so one strict pattern can reject valid formats and one permissive pattern can accept invalid values.

Table of Contents

Information

  • Hits329
  • Published date2026/08/28
0/500
Share your thoughts respectfully.

More Posts

Explore more articles from this section
Regex for IP Addresses: Accurate IPv4 and IPv6 Validation Examples
Sep 09, 2026450views

Regex for IP Addresses: Accurate IPv4 and IPv6 Validation Examples

Use regex to find possible IP addresses, then use the right validation rule for the job. This guide covers loo...

#regex for IP address#IP address regex#IPv4 regex#IPv6 regex
Password Validation Regex: Examples for Length, Numbers, Symbols, and Strong Passwords
Sep 07, 2026447views

Password Validation Regex: Examples for Length, Numbers, Symbols, and Strong Passwords

Learn practical password validation regex patterns for length, digits, symbols, and mixed character classes. T...

#password validation regex#regex for password validation#strong password regex#regex lookahead
How to Validate a URL with Regex: HTTP, HTTPS, Domains, and Query Strings
Sep 03, 2026385views

How to Validate a URL with Regex: HTTP, HTTPS, Domains, and Query Strings

Build a practical HTTP and HTTPS URL regex by separating schemes, DNS domains, ports, paths, query strings, an...

#URL validation regex#regex for URL validation#HTTP URL regex#HTTPS URL regex
How to Extract Email Addresses from Text with Regex in Python and JavaScript
Sep 15, 2026345views

How to Extract Email Addresses from Text with Regex in Python and JavaScript

Extract email addresses from any text with regex in Python and JavaScript: the pattern explained piece by piec...

#regex extract email#email regex python#email regex javascript#extract emails from text
How to Replace Text with Python Regex: re.sub() Examples and Common Mistakes
Sep 18, 2026323views

How to Replace Text with Python Regex: re.sub() Examples and Common Mistakes

Learn how to replace text safely with Python re.sub(), including capture groups, callback functions, case-inse...

#python regex replace#re.sub#regex capture groups#regex callback
Regex for Numbers Only: Integers, Decimals, Negative Values, and Leading Zeros
Sep 12, 2026312views

Regex for Numbers Only: Integers, Decimals, Negative Values, and Leading Zeros

Choose the right regex for numbers-only input. This guide covers ASCII digits, integers, decimals, negative va...

#regex for numbers only#numbers only regex#integer regex#decimal regex
Feedback email