Phone Number Regex: US, E.164, UK, India (Tested)
Phone number regex for US, E.164, UK and India, run in Node and Python on 80 labelled strings and 200,000 random numbers, with false positives counted against libphonenumber.
On this page ⌄
- Regex to validate a phone number: four patterns
- The labelled test set (80 strings)
- What is the syntax of a US phone number?
- Regex for a 10 digit phone number
- How often the regexes accept numbers that do not exist
- Format leniency: where the library accepts more than your regex
- Extensions and extracting numbers from text
- Is regex safe on long input? Backtracking timing
- Where regex stops: libphonenumber
- FAQ
- Tested
- Sources
Use a regex to check that a string has the shape of a phone number: right characters, right length, legal first digits. A regex cannot tell whether the number is assigned or reachable. In a test of 200,000 random 10-digit strings, the NANP-shaped regex below accepted 128,117, and Google's libphonenumber data says 56,196 of those are not valid US numbers. The patterns, the labelled test set and the measurements follow, all run in Node and Python.
Regex to validate a phone number: four patterns
| Format | Regex | Notes |
|---|---|---|
| US / Canada (NANP) | ^(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$ | Area code and exchange start with 2 to 9 |
| E.164 | ^\+[1-9]\d{1,14}$ | Plus sign, country code, 2 to 15 digits in total, no separators |
| UK mobile | ^(?:\+44|0)7[1-57-9]\d{8}$ | Run after stripping spaces and hyphens |
| India mobile | ^(?:\+91|0)?[6-9]\d{9}$ | Run after stripping spaces and hyphens |
In a markdown table the pipe is written \|. In code it is a plain |.
Why these shapes:
- NANP (the US, Canada and Caribbean plan): numbers are written NXX NXX-XXXX, where N is a digit from 2 to 9 and X is any digit. The area code and exchange cannot start with 0 or 1, and an exchange of the form N11 (such as 911) is a service code, not an exchange (Wikipedia: North American Numbering Plan).
- E.164: plan-conforming numbers are limited to digits and a maximum of fifteen of them (Wikipedia: E.164); the ITU lists E.164 (02/26) as in force on its recommendation page. Country calling codes belong to world zones 1 to 9, so the first digit is never 0 (Wikipedia: list of country calling codes has no zone 0). The 15-digit limit is quoted from Wikipedia's summary, not from the ITU PDF. The regex needs at least two digits, so
+1alone fails. - UK mobile: a UK mobile number has ten digits after the trunk 0, so 11 digits when dialled domestically and
+44 7xxx xxxxxxinternationally. Within07, the ranges070(personal numbers) and076(pagers, except 07624 for the Isle of Man) are not mobile, so the pattern allows071to075and077to079(Wikipedia: Telephone numbers in the United Kingdom). Remove the[1-57-9]restriction (use\d) if you also want to accept personal and pager numbers. Limit: the pattern also rejects07624numbers, which are Isle of Man mobiles (libphonenumber reports+44 7624 123456as a valid mobile for region IM); add|07624\d{6}after the prefix group if you need them. - India mobile: a 10-digit national number with trunk prefix 0 (Wikipedia: Telephone numbers in India). The
[6-9]first digit is the common convention for mobile ranges and is a heuristic here, not a rule taken from the numbering plan text.
The UK and India patterns assume you first remove spaces and hyphens (s.replace(/[\s-]/g, '')), because people group digits in many ways and listing every grouping in the regex is harder than stripping. E.164 is deliberately strict: it is a storage format, so +1 202 555 0147 fails it.
Phone number regex in JavaScript
const strip = (s) => s.replace(/[\s-]/g, '');
const US = /^(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$/;
const E164 = /^\+[1-9]\d{1,14}$/;
const UK_MOBILE = /^(?:\+44|0)7[1-57-9]\d{8}$/;
const IN_MOBILE = /^(?:\+91|0)?[6-9]\d{9}$/;
US.test('(202) 555-0147'); // true
US.test('(202 555-0147'); // false (unbalanced parenthesis)
E164.test('+12025550147'); // true
UK_MOBILE.test(strip('07911 123456')); // true
IN_MOBILE.test(strip('+91 98765 43210')); // true
In JavaScript, \d is equivalent to [0-9], so Arabic-Indic and other Unicode digits do not match, and $ without the m flag matches only at the very end of the string (MDN: character classes). Note that \s also matches a non-breaking space and other Unicode spaces.
Python phone regex: use fullmatch and re.ASCII
Python differs from JavaScript in two ways that matter for validation (Python re documentation): $ also matches just before a trailing newline, and \d on a str pattern matches any Unicode decimal digit. Use re.fullmatch with re.ASCII:
import re
US = re.compile(r"^(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}$", re.ASCII)
E164 = re.compile(r"^\+[1-9]\d{1,14}$", re.ASCII)
bool(US.fullmatch("202.555.0147")) # True
bool(E164.fullmatch("12025550147")) # False (no plus sign)
Measured on Python 3.11 with the same patterns: re.match accepted "202-555-0147\n" and "202-555-١٢٣٤" (Arabic-Indic digits) as US numbers, and re.match accepted "+12025550147\n" as E.164. fullmatch with re.ASCII rejected all three, and Node's RegExp.test rejected them too.
The labelled test set (80 strings)
Each string has a label written from the rules above (should the regex accept it?), not from any tool's output. The full set has 29 strings that should match and 51 that should not, and it was run through Node and Python (fullmatch with re.ASCII). Both gave the same answer on all 80 strings and agreed with the labels. The table shows a representative selection of 53 of them; the rest are further variants of the same cases (extra separators, letters in place of digits, a wrong country prefix, +12 as the shortest legal E.164 shape).
| Pattern | Should match | Should NOT match |
|---|---|---|
| US | (202) 555-0147, 202-555-0147, 202.555.0147, 2025550147, +1 202 555 0147, 1-202-555-0147, 1 (202) 555-0147 | (202 555-0147, 202-555-014, 012-555-0147, 102-555-0147, 202-155-0147, 202-055-0147, 202--555-0147, 2025550147 (trailing space), 202-555-0147 plus a trailing newline, Arabic-Indic digits, empty string |
| E.164 | +12025550147, +447911123456, +919876543210, +8613812345678, +123456789012345 (15 digits) | +1 202 555 0147, 12025550147, +0123456789, +1234567890123456 (16 digits), +, ++12025550147, +1, +1-202-555-0147 |
| UK mobile (stripped) | 07911 123456, +44 7911 123456, +447911123456, 07911-123-456 | 07911 12345, 06911 123456, 07911 1234567, 07011 123456, 07611 123456, 020 7946 0958, +44 (0)7911 123456, 7911 123456 |
| India mobile (stripped) | 98765 43210, +91 98765 43210, +91-9876543210, 09876543210, 6000000000 | 98765 4321, 12345 67890, +91 5876543210, +91 98765 432101, +91 22 2345 6789 |
You can paste any of these into the Regex Tester with a pattern from the table to see the match highlighted.
What is the syntax of a US phone number?
A 10-digit number written NXX NXX-XXXX: a three-digit area code (first digit 2 to 9), a three-digit exchange (first digit 2 to 9, not N11) and a four-digit line number. The country code is +1, and the usual written forms are (202) 555-0147, 202-555-0147, 202.555.0147 and +1 202 555 0147. The first regex in the table accepts all of those.
Regex for a 10 digit phone number
For NANP: ^[2-9]\d{2}[2-9]\d{6}$. A plain ^\d{10}$ accepts anything of that length, including 0000000000 and 1234567890. Their effect on random input is in the next section.
How often the regexes accept numbers that do not exist
Reference: phonenumbers 9.0.42, the Python port of Google's libphonenumber (python-phonenumbers), whose is_valid_number checks a number against an assigned numbering pattern, while is_possible_number only checks length. The reference is itself metadata-based, not ground truth.
Experiment 1: 200,000 random 10-digit strings (every digit uniform, random.seed(1117)), each checked against is_valid_number for +1. Uniform digits are a worst case, not a model of what real users type.
| Regex | Accepted | Valid per libphonenumber | Accepted but not valid | Valid but rejected |
|---|---|---|---|---|
^\d{10}$ | 200,000 | 72,020 | 127,980 | 0 |
^[2-9]\d{2}[2-9]\d{6}$ | 128,117 | 71,921 | 56,196 | 99 |
| same, also rejecting N11 area codes and exchanges | 125,552 | 71,223 | 54,329 | 797 |
Reading it: a regex that only knows the NANP shape still lets through about 44% of what it accepts, because only 455 of the 800 possible area codes (the area-code digits 200 to 999) were valid in the library data when tested with the exchange 234-5678, and no N11 area code was valid. The 99 numbers valid per the library but rejected by the NANP regex were all 8xx numbers with an exchange starting 0 or 1: the library's data accepts an exchange beginning 0 or 1 in many 8xx area codes, which the NANP exchange rule above does not allow. Counts this small shift with the random seed (an independent run with another seed gave 136 and 712 instead of 99 and 797); the structure stays the same. The stricter N11 variant rejects 797 numbers the library accepts (exchanges such as 911 and 611), so it is more faithful to the NANP rule but less compatible with libphonenumber. Decide which one you want and do not call either one "validation of real numbers".
Two edge cases from the same run: 202-555-0100 through 0199 all pass the regex and the library, even though that block is the one the numbering administrator reserves for fictional use ("The fictitious, non-working numbers, 555-0100 through 555-0199, will remain reserved for entertainment/advertising", NANPA: 555 line numbers), which is why the examples on this page use (202) 555-0147; and +1 555 234 5678 has a possible length but fails is_valid_number, because 555 is not an assigned area code.
Experiment 2 (UK): 200,000 random numbers of the form 07 plus 9 digits. With the loose pattern ^(?:\+44|0)7\d{9}$, the library marked 14,560 (7.3%) as invalid, almost all in 076. With the pattern in the table (07[1-57-9]), it accepted 159,891 numbers and 210 of them (0.13%) were not valid per the library, all in single blocks such as 07700 and 07911. The same restriction rejected 25,604 numbers that the library calls valid, mainly personal (070) and pager (076) numbers, which is the intent.
Experiment 3 (India): every one of 200,000 random [6-9]\d{9} numbers was valid per the library, but the library types only about 67% of them as mobile; about 15% were fixed-line and about 18% were "fixed line or mobile". A first digit of 6 to 9 therefore does not prove a mobile number.
Format leniency: where the library accepts more than your regex
On the 80-string set, libphonenumber is_valid_number (with the region implied by the pattern, None for E.164) accepted 21 of the 51 strings labelled as should-not-match. These were formatting cases such as (202 555-0147, 202--555-0147, a trailing space, a trailing newline, Arabic-Indic digits, +1-202-555-0147, +44 (0)7911 123456 and 12345 67890 (a valid India fixed-line number) and 07011 123456 (a UK personal number). It also rejected 2 of the 29 should-match strings: +12 and the 15-digit +123456789012345, which have a legal E.164 shape but are not assigned numbers.
So the library is more permissive about formatting and stricter about numbering. For a signup form, parse and check with the library, then store the E.164 string; keep the regex for a quick client-side hint.
Extensions and extracting numbers from text
For an optional extension add (?:\s*(?:x|ext\.?|extension)\s*\d{1,5})? before the $. A form field is better as two inputs (number and extension), which keeps the main pattern simple.
Validation anchors with ^ and $. Extraction cannot, so it needs guards against digits glued to neighbours:
const US_FIND = /(?<![\d-])(?:\+?1[\s.-]?)?(?:\([2-9]\d{2}\)|[2-9]\d{2})[\s.-]?[2-9]\d{2}[\s.-]?\d{4}(?:\s*(?:x|ext\.?|extension)\s*\d{1,5})?(?!\d)/g;
const text = 'Call (202) 555-0147 ext. 45 or 303.555.0188 x12. Order 4155550123, ZIP 94105-1234, date 2026-11-02, ref 123-456-7890, tracking 1234567890.';
[...text.matchAll(US_FIND)].map(m => m[0]);
// [ '(202) 555-0147 ext. 45', '303.555.0188 x12', '4155550123' ]
Python re.finditer returns the identical list, and so does phonenumbers.PhoneNumberMatcher(text, "US"). The ZIP+4, the date, the reference starting with 1 and the tracking number were all rejected, but the order number 4155550123 was extracted by all three: it has the shape of a valid US number, so no regex can tell it apart. Use context (a label such as "tel" or "phone") if false positives matter.
Is regex safe on long input? Backtracking timing
None of the patterns above nests a quantifier inside another, so they cannot backtrack catastrophically. Each regex was run (Node 25.8 and Python 3.11, with and without the strip step) on 200,000-character inputs: 1 repeated, 2- repeated, only spaces, only +, only (, a valid prefix followed by 200,000 digits, and 1 . repeated. The slowest run in Node was 1.0 ms and in Python under 0.1 ms.
For contrast, the common mistake ^(\d+[\s-]?)+$ on 28 digits followed by x took roughly 3 to 4 s in Node and 40 to 75 s in Python (Node: 0.19 s at 24 digits and 3.3 to 3.8 s at 28 digits over four runs; Python: 2.5 to 4.1 s at 24 digits and 44 to 75 s at 28 digits over several runs, with timings varying by machine load, so treat the figures as order of magnitude). If you write your own phone pattern, never wrap an optional separator inside a repeated group.
Where regex stops: libphonenumber
libphonenumber is Google's library for parsing, formatting and validating international numbers (libphonenumber on GitHub); it has Java, C++ and JavaScript versions, plus ports such as phonenumbers for Python and libphonenumber-js. Its own notes recommend using the library for country-specific rules and warn that a number that connects today may be disconnected tomorrow (libphonenumber FALSEHOODS). A valid number is therefore not proof that someone owns it; verification needs an SMS or call.
import phonenumbers as pn
n = pn.parse("+447911123456")
pn.is_valid_number(n) # True
pn.format_number(n, pn.PhoneNumberFormat.INTERNATIONAL) # '+44 7911 123456'
pn.format_number(n, pn.PhoneNumberFormat.NATIONAL) # '07911 123456'
Once a number validates, the Phone Number Formatter converts raw digits and a country code into E.164, national, international and RFC 3966 (tel:) forms in the browser.
FAQ
What is the regex for a phone number with a country code?
For any country, E.164: ^\+[1-9]\d{1,14}$. For US and Canadian numbers with an optional country code, the NANP pattern above accepts +1, 1- or nothing.
What is a phone number regex for JavaScript?
The same patterns work in JavaScript. Use .test() on a string, and double the backslashes inside a string passed to new RegExp. JavaScript's \d is ASCII-only, so no extra flag is needed.
What is the regex for a 10 digit phone number?
^[2-9]\d{2}[2-9]\d{6}$ for NANP. ^\d{10}$ accepts any 10 digits, and in the random test above 64% of those were not valid US numbers.
Can you provide a regex pattern for validating mobile numbers? Yes, per country: the UK and India patterns above work on stripped input. A single global mobile regex does not exist, because mobile ranges differ per country and some ranges are shared with fixed lines.
What is the regex for a number?
^[0-9]+$ matches digits only. Prefer [0-9] over \d in Python, where \d matches other Unicode digits unless you pass re.ASCII.
Should I validate phone numbers with regex? Use regex for shape checks and input hints, and libphonenumber for anything that matters.
Tested
Run on 2026-11-17 with Node 25.8.0, Python 3.11.15 and phonenumbers 9.0.42. The 80-string set was executed in Node and Python with identical results and zero differences from the labels. The random samples used random.seed(1117) with 200,000 draws per experiment. libphonenumber results come from the Python port only; libphonenumber-js was not run. The UK 07[1-57-9] rule and the India [6-9] convention were not checked against the regulators' own numbering plans: Ofcom's numbering pages returned HTTP 403 and the Indian National Numbering Plan 2003 PDF could not be reached on that date. The NXX and N11 rules rest on Wikipedia, and the 555-0100 to 0199 range comes from NANPA's own page. Mobile reachability and whether numbers are assigned to a subscriber were not tested.
Sources
- NANPA: 555 line numbers: 555-0100 through 555-0199 reserved for entertainment and advertising use (primary source).
- Wikipedia: North American Numbering Plan: NXX NXX-XXXX structure (N = 2 to 9), no N11 central office code. The NANPA planning documents for these two rules were not retrievable, so they rest on this secondary source.
- ITU-T E.164 (in-force version 02/26, approved 2026-02-13) and Wikipedia: E.164: fifteen-digit maximum; Wikipedia: list of country calling codes: zones 1 to 9.
- Wikipedia: Telephone numbers in the United Kingdom: 07 ranges for mobile, personal (070) and pager (076, excluding 07624) numbers.
- Wikipedia: Telephone numbers in India: 10-digit numbers, trunk prefix 0.
- Python re documentation:
$,fullmatch, Unicode\d,re.ASCII. - MDN: Regular expression character classes:
\dand\sin JavaScript. - google/libphonenumber and its FALSEHOODS note; python-phonenumbers:
is_valid_numberversusis_possible_number.
Related tools
Phone Number Formatter
Enter raw digits and a country code to format phone numbers into E.164, national, international and RFC3966 styles.
Hours Calculator
Add start, end and break times for each day to see daily hours, weekly totals and overtime instantly.
Character Counter
Count characters, words, sentences, lines and UTF-8 bytes with live SEO and social media limit tracking.
Keyboard Test
Press any key to see it light up and find dead, stuck or double-typing keys, with rollover checks for full size, TKL and 75% layouts.
Written by Mian Ali Khalid. More guides in Dev Productivity.