Skip to main content
Free developer tool

This phone number regex tester shows which numbers your pattern really lets through.

The safest phone number regex is E.164, ^\+[1-9]\d{1,14}$, tested on numbers stripped of spaces. Paste any pattern below: each line gets the regex's answer and the numbering plan's answer side by side, so you see the fakes it lets through and the real numbers it turns away. It all runs in your browser.

Start from a pattern

A 10-digit North American number in any common style, with or without the leading 1. Judged as a US and Canada pattern, so other numbers should not match.

Only used for the numbering plan's answer. The regex sees exactly what you typed.

Results

  • (201) 555-0123MatchesChecking the plan...
  • 201-555-0123MatchesChecking the plan...
  • +1 201 555 0123MatchesChecking the plan...
  • 211-555-0123MatchesChecking the plan...
  • 101-555-0123No matchChecking the plan...
  • 555-0123No matchChecking the plan...
const phoneRegex = /^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/;
phoneRegex.test("(201) 555-0123"); // true

A pattern checks the shape. Only the network knows if the line is switched on.

Check any mobile number live, free: active, unreachable or no active line.

These six phone number patterns cover most forms, and each one has a gap.

Pick the one that matches what your form accepts. The gap is what to handle outside the regex.

E.164, any country

^\+[1-9]\d{1,14}$

Numbers already stored in E.164: a plus, a country code and up to 15 digits, nothing else.

It checks the shape only, so +15555550123 passes although no US area code starts with 555.

US and Canada

^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$

A 10-digit North American number in any common style, with or without the leading 1.

It lets through area codes that do not exist, such as 211 and 555, because it only checks the first digit.

UK mobile

^(?:\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$

A UK mobile written as 07400 123456 or +44 7400 123456.

Every 07 number passes, including 070 personal numbers, which are not mobiles and often cost more to call.

India mobile

^(?:\+?91[\-\s]?|0)?[6-9]\d{4}[\-\s]?\d{5}$

A 10-digit Indian mobile that starts with 6, 7, 8 or 9, with +91 or 0 in front or neither.

It accepts any 10 digits that start with 6 to 9, including blocks that have never been assigned.

Australia mobile

^(?:\+?61\s?|0)4\d{2}\s?\d{3}\s?\d{3}$

An Australian mobile written as 0412 345 678 or +61 412 345 678.

It turns away the same number written with dashes or brackets, which people type more often than you would think.

Loose, any format

^\+?[\d\s\-().]{7,20}$

The pattern most forms start with: 7 to 20 digits, spaces, dashes, dots and brackets.

It counts characters, not digits, so a line of dashes or brackets passes as a phone number.

We ran all 6 patterns against the same 17 numbers, and 5 of them got at least one wrong.

Each pattern is judged only on what it is for: the US pattern is right to refuse a UK number, and a mobile pattern is right to refuse a landline. The numbering plan's answer comes from libphonenumber's full metadata, computed when this page was built. Red is a number let through that should not be; amber is a real one turned away.

NumberNumbering plan saysE.164, any countryUS and CanadaUK mobileIndia mobileAustralia mobileLoose, any format
+12015550123US, stored as E.164Real landline or mobile, USaccepts, rightaccepts, rightrejects, rightrejects, rightrejects, rightaccepts, right
(201) 555-0123US, with bracketsReal landline or mobile, USrejects, rightaccepts, rightrejects, rightrejects, rightrejects, rightaccepts, right
201.555.0123US, with dotsReal landline or mobile, USrejects, rightaccepts, rightrejects, rightrejects, rightrejects, rightaccepts, right
1-201-555-0123US, leading 1Real landline or mobile, USrejects, rightaccepts, rightrejects, rightrejects, rightrejects, rightaccepts, right
211-555-0123211 is not an area codeNot a real numberrejects, rightaccepts, wrongrejects, rightrejects, rightrejects, rightaccepts, wrong
+15555550123555 is not an area codeNot a real numberaccepts, wrongaccepts, wrongrejects, rightrejects, rightrejects, rightaccepts, wrong
555-0123No area codeNot a real numberrejects, rightrejects, rightrejects, rightrejects, rightrejects, rightaccepts, wrong
+1 201 555 01234One digit too manyNot a real numberrejects, rightrejects, rightrejects, rightrejects, rightrejects, rightaccepts, wrong
07400 123456UK mobileReal mobile, GBrejects, rightrejects, rightaccepts, rightrejects, rightrejects, rightaccepts, right
+44 7400 123456UK mobile, internationalReal mobile, GBrejects, rightrejects, rightaccepts, rightrejects, rightrejects, rightaccepts, right
07000 123456UK 070 personal numberReal personal number, GBrejects, rightrejects, rightaccepts, wrongrejects, rightrejects, rightaccepts, right
+91 81234 56789India mobileReal mobile, INrejects, rightrejects, rightrejects, rightaccepts, rightrejects, rightaccepts, right
0412 345 678Australia mobileReal mobile, AUrejects, rightrejects, rightrejects, rightrejects, rightaccepts, rightaccepts, right
0412-345-678Australia mobile, dashesReal mobile, AUrejects, rightrejects, rightrejects, rightrejects, rightrejects, wrongaccepts, right
+49 1512 3456789Germany mobileReal mobile, DErejects, rightrejects, rightrejects, rightrejects, rightrejects, rightaccepts, right
--------Only dashesNot a phone numberrejects, rightrejects, rightrejects, rightrejects, rightrejects, rightaccepts, wrong
+0 201 555 0123Country code 0Not a phone numberrejects, rightrejects, rightrejects, rightrejects, rightrejects, rightaccepts, wrong
Wrong answers121016

The test numbers are the numbering plans' own example numbers and broken copies of them. None belongs to a person.

The E.164 pattern needs a different guard in each language.

The same pattern behaves differently from one regex engine to the next: Python, PHP and .NET let a trailing newline through, and Python and .NET read non-Latin digits as \d. Each snippet closes the gap its language has. The tester above writes the same code for any pattern you type.

Phone number regex in JavaScript
const phoneRegex = /^\+[1-9]\d{1,14}$/;
phoneRegex.test("+12015550123"); // true
Phone number regex in Python
import re

PHONE = re.compile(r"^\+[1-9]\d{1,14}$")
# fullmatch, not match: $ also matches before a final newline in Python
bool(PHONE.fullmatch("+12015550123"))  # True
Phone number regex in PHP
<?php
// The D modifier stops $ matching before a final newline
$ok = preg_match('/^\+[1-9]\d{1,14}$/D', '+12015550123') === 1;
Phone number regex in Java
import java.util.regex.Pattern;

Pattern PHONE = Pattern.compile("^\\+[1-9]\\d{1,14}$");
// matches() needs the whole string, so no anchor surprises
boolean ok = PHONE.matcher("+12015550123").matches();
Phone number regex in C#
using System.Text.RegularExpressions;

// In .NET, \d also matches non-ASCII digits and $ matches before a final \n:
// trim the input first, or use [0-9] and end the pattern with \z
var phone = new Regex(@"^\+[1-9]\d{1,14}$");
bool ok = phone.IsMatch("+12015550123");
Phone number regex in Go
import "regexp"

var phone = regexp.MustCompile(`^\+[1-9]\d{1,14}$`)
ok := phone.MatchString("+12015550123")

Checking a phone number takes three layers, and a regex is only the first.

Every layer catches what the one before it cannot. Most sign-up fraud and bounced texts get through the first.

  1. 1. Shape

    A regex

    Digits, length and punctuation look like a phone number. Free, instant, and blind to whether the area code exists.

  2. 2. Numbering plan

    libphonenumber

    The country hands out numbers like this one, and whether it is a mobile, landline or toll-free range.

    Try it free
  3. 3. The live line

    HLR lookup or an API

    The number is switched on today, which network it is on now, and whether it is a mobile, landline or VoIP line.

    Try it free

These are the questions developers ask most about phone number regex.

What is the best regex for a phone number?

For numbers you store, use E.164: ^\+[1-9]\d{1,14}$. It accepts a plus, a country code that does not start with 0 and up to 15 digits, which is every phone number in the world written the one way APIs expect. Strip spaces, dashes and brackets before you test it, and format the number for people only when you show it.

What is the regex for a US phone number?

^(?:\+?1[-. ]?)?\(?([2-9][0-8][0-9])\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$ accepts a 10-digit US or Canadian number with or without the leading 1, in brackets, dashes, dots or spaces. It checks that the area code and exchange start with 2 to 9, but not that the area code exists, so 211 and 555 area codes pass. The table on this page shows exactly which.

Can a regex validate a phone number?

Only its shape. A regex cannot know which area codes and prefixes a country really hands out, so it lets through numbers that cannot exist, and it cannot know whether a number is switched on today. A numbering plan library such as libphonenumber answers the first question, and a live network lookup (HLR) answers the second.

Why does my phone regex accept a number with a newline at the end?

In Python, PHP and .NET, $ also matches just before a final newline, so ^...$ lets "2015550123\n" through. Use re.fullmatch in Python, add the D modifier in PHP, and end the pattern with \z or trim the input in .NET. JavaScript, Java's matches() and Go do not have this problem.

Why does \d match digits that are not 0 to 9?

In Python 3 and .NET, \d matches any Unicode decimal digit, including Arabic-Indic and Devanagari digits, so a form can accept a number your SMS provider cannot read. Write [0-9] instead of \d, or convert the digits first. JavaScript, Java and Go match only 0 to 9 with \d.

Is 555-0123 a real phone number?

No. In North America, 555-0100 to 555-0199 are set aside for films, books and examples, so no one answers them. Every pattern on this page accepts 201-555-0123, and so does libphonenumber, because the digits fit the numbering plan. Only a live check of the line shows nobody is there.

These free tools take a phone number further than a regex can.

One API call checks the shape, the plan and the live line.

The 1Lookup phone API returns whether a number is valid, its line type, its carrier and whether it is reachable, in one request. Start with a 7-day free trial.

Get a free API key