1. Home
  2. Free tools
  3. Phone number tools
  4. Phone number regex tester

Phone number regex: tested patterns for E.164, US and UK, with a tester

The standard phone number regex for an international number in E.164 format is ^\+[1-9]\d{1,14}$: a plus, a first digit from 1 to 9, and up to 15 digits. A regex can only check that shape. Paste numbers above to see which ones each pattern accepts and which of those libphonenumber rejects as numbers that can't exist.

Runs in your browser. Nothing is uploaded.

Used for numbers written without a + country code.

JavaScript syntax, no slashes. Your pattern runs in a separate worker and is stopped after 3 seconds if it hangs.

Copy a pattern

A +, a first digit from 1 to 9 and at most 15 digits in all, with no spaces or punctuation. Use it on stored, normalised values. It accepts +999999999999, which is no number anywhere.

^\+[1-9]\d{1,14}$
const PHONE_RE = /^\+[1-9]\d{1,14}$/;

export function isPhoneShaped(value) {
  return PHONE_RE.test(value.trim());
}

Better: validate with libphonenumber

Parses any formatting, checks the number against the country’s numbering plan and returns E.164 for storage.

// npm install libphonenumber-js
import { parsePhoneNumberFromString } from "libphonenumber-js/max";

export function toE164(value, defaultCountry = "US") {
  const phone = parsePhoneNumberFromString(value, defaultCountry);
  return phone?.isValid() ? phone.number : null; // "+14155552671" or null
}
Sample result from the Phone number regex tester
Show the sample result as

Sample result

+15551234567 passes the E.164 pattern but isn't a valid number.

Tested value
+15551234567
E.164 pattern
Match
libphonenumber
Not a valid number

What this means for you

A regex only checks the shape; use a numbering-plan check before you trust a number.

Next step:Validate the number properly
  • E.164, NANP, UK and loose input patterns
  • Bulk tester against each pattern at once
  • Shows matches that aren't real numbers
  • Copy-ready code in JavaScript, Python and PHP
  • Regex
  • E.164
  • Code

By SimpleVerifier Team · Last updated · Runs in your browser; nothing you paste is sent to us

How do I test a phone number regex?

  1. Paste numbers, one per line, or press Try an example for a set of edge cases.
  2. Choose the country used for numbers written without a +, and optionally add your own pattern.
  3. Press Test numbers. Each row shows a tick or cross per pattern and libphonenumber's verdict; rows that match a regex but are invalid are the ones a regex would wrongly accept.
  4. Under Copy a pattern, pick a pattern and a language and copy the code, or copy the libphonenumber version for real validation.

Example

You enter
Two values, +14155550132 and +15551234567.
You get
Both match the E.164 pattern, but libphonenumber says only +14155550132 is a valid number (US); +15551234567 is the kind of value a regex wrongly accepts.
Limits
Uploaded files can be up to 25 MB; there is no cap on the number of rows, and it all runs in your browser.

What is the regex for a phone number?

There isn't one regex for every phone number, because every country writes numbers differently; pick the pattern for the format you expect. For stored numbers in E.164 form use ^\+[1-9]\d{1,14}$. E.164 caps an international number at 15 digits including the country code, and no country code starts with 0, which is all this pattern encodes.

For US and Canadian numbers typed by people, the NANP pattern on this page accepts (415) 555-2671, 415.555.2671 and +1 415 555 2671, and requires the area code and the exchange to start with 2 to 9, as the North American Numbering Plan does. The UK pattern accepts +44 or a leading 0, an optional (0), and 9 or 10 further digits. For a form field that should take any country, the loose filter only blocks letters and obvious junk.

How do I write a regex for a phone number with a country code?

Make the country code an optional group at the start: (?:\+?1[ .-]?)? lets a US pattern accept +1 415…, 1-415… or 415…. For any country, the cleaner route is to normalise first and then match E.164: strip spaces and punctuation, add the country code, and test ^\+[1-9]\d{1,14}$. The add or remove country code tool and the phone number formatter do the normalising for a whole list.

Don't try to list every country's code and length in one pattern. The numbering plans change every year, and a pattern that tries to encode them is long, slow to read and out of date the day it ships. That's what numbering-plan libraries are for.

How do I validate a phone number with regex in JavaScript, Python or PHP?

Use an anchored pattern and test the trimmed value, as the snippets on this page do. In JavaScript that's PHONE_RE.test(value.trim()); in Python use re.fullmatch, which anchors both ends; in PHP add the D modifier so $ doesn't also accept a trailing newline. The patterns here avoid lookarounds and backreferences, so the same source string behaves the same in all three.

Then validate on the server with a library. Google's libphonenumber and its ports (libphonenumber-js, phonenumbers for Python, libphonenumber-for-php) parse any formatting and return the number in E.164. The code under Better: validate with libphonenumber is ready to copy. Our guides cover JavaScript and Python in more depth.

Is regex enough to validate a phone number?

No. A regex checks that the characters and length look right; it can't know which ranges a country has allocated. +15551234567 passes the E.164 pattern though 555 isn't an assigned area code, and +999999999999 passes though no country uses +999. The tester above shows how many of your own numbers fall into that gap.

Even libphonenumber only tells you a number can exist. It can't say the line is connected, who carries it today or whether it's a mobile in countries such as the US, where mobiles and landlines share ranges. libphonenumber's own falsehoods list is a good read before you write any phone validation. For line type and carrier, see phone carrier lookup.

Which is better for phone validation, regex or libphonenumber?

Regexlibphonenumber
Accepts any formattingOnly what the pattern spells outYes
Knows which ranges are allocatedNoYes, per country
Rejects +15551234567No (E.164 pattern)Yes
Returns E.164 for storageNoYes
Mobile or landlineNoWhere the plan separates them
SizeOne lineA library and metadata

Use a loose regex in the input field and libphonenumber on submit or on the server.

Who uses this tool, and for what?

Front-end developers
Pick a loose pattern for the input field that won't reject real numbers typed with brackets or spaces, and see exactly what it lets through.
Back-end developers
Copy one pattern that behaves the same in the JavaScript client and the Python or PHP server, then swap in the libphonenumber code for the server-side check.
QA engineers
Paste a list of edge cases and keep the downloaded CSV as the expected results for tests.
Data and CRM teams
Test an exported phone column to see how many values a regex rule would pass that aren't valid numbers, before you trust that rule in a data-quality check.

What can’t this tool tell you?

  • A regex match only means the shape is right. It can't tell whether a range is allocated, and nothing on this page can tell whether a line is connected.
  • libphonenumber's verdict uses the metadata bundled with the page, so ranges opened very recently may show as invalid until the data updates.
  • Numbers written without a + are read in the country you choose, so a UK number like 020 7946 0958 shows as invalid with the US selected.
  • Your own pattern runs with JavaScript semantics; Python and PHP differ on a few features, such as named groups.
  • Extensions (ext. 42) aren't part of E.164 and fail every pattern here.

Common questions

What is the regex for a phone number?
It depends on the format. For E.164, the international storage format, use ^\+[1-9]\d{1,14}$. For US numbers with punctuation, use the NANP pattern on this page. No single regex covers every country's written formats.
How do I write a regex for a phone number?
Decide the exact format you accept, anchor the pattern with ^ and $, and make punctuation optional with groups like [ .-]?. Then test it against real numbers, as the tester above does, before you ship it.
What is the regex for a phone number with a country code?
Make the code an optional group at the start, such as (?:\+?1[ .-]?)? for the US. For numbers from any country, normalise to E.164 first and match ^\+[1-9]\d{1,14}$.
What is the regex for a phone number with dashes?
For US numbers, ^[2-9]\d{2}-[2-9]\d{2}-\d{4}$ requires the 415-555-2671 form. The NANP pattern on this page also accepts dashes, along with spaces, dots and brackets.
What is E.164 format?
The ITU-T standard for international phone numbers: a +, the country calling code and the national number with no spaces or punctuation, at most 15 digits in total. +14155552671 is a US number in E.164.
What is the regex for phone number validation in JavaScript?
Use an anchored literal and test the trimmed input, for example /^\+[1-9]\d{1,14}$/.test(value.trim()) for E.164. For real validation, use libphonenumber-js: parsePhoneNumberFromString(value, 'US')?.isValid().
What is the regex for a phone number in Python?
Compile the pattern and use fullmatch: re.compile(r'^\+[1-9]\d{1,14}$').fullmatch(value.strip()). For validation, the phonenumbers package parses the number and checks it against the numbering plan.

Sources

Well formatted is not the same as reachable.

This tool fixes how numbers are written. It cannot tell you whether a line is mobile, landline or VoIP, or which carrier holds it. That takes a live carrier lookup, which is what the Email + Phone plan adds.

  • Upload a CSV up to 100,000 rows with an email or phone column
  • 5,000 live carrier lookups a month: carrier name and real line type
  • Emails in the same file get a real SMTP mailbox check

One plan, cancel anytime, no contract. Sign in with Google and your first 100 email checks are free, no card. The free tools stay free either way.

Clean your next list before it bounces

100 free email checks when you sign in with Google, no card. Then one flat monthly price, or a one-time pack.

7-day money-back guarantee Cancel anytime Secure payment by Stripe