Regex for phone numbers
A regular expression for phone numbers in international E.164 format, variants for UK numbers, and why the reliable approach is to normalise first and validate with a numbering library.
This tool runs in your browser. We never send what you type or paste to a server.
The pattern
/^\+[1-9][0-9]{1,14}$/E.164 is the ITU's international numbering plan. A number in E.164 form is a plus sign, a country code of one to three digits and the national number without its leading 0, at most 15 digits in all and with no spaces or punctuation. It is the best form to store, because it is unambiguous and every telephony API accepts it.
The tester at the top of this page is loaded with this pattern and the examples below, one per line. It adds the m flag so that ^ and $ apply to each line, and g to show every match. Edit either box to try your own input.
How it works, token by token
| Part | Meaning |
|---|---|
^ | Start of the string. |
\+ | A literal plus sign. + on its own means "one or more", so it is escaped. |
[1-9] | The first digit of the country code. No country code starts with 0. |
[0-9]{1,14} | The rest of the number: between 1 and 14 more digits, so 15 digits at most in total. |
$ | End of the string. |
What it matches and what it rejects
| Input | Result | Why |
|---|---|---|
+441134960123 | matches | A UK landline in E.164 form. |
+447700900123 | matches | A UK mobile. |
+12015550123 | matches | A North American number: country code 1. |
+8613800138000 | matches | Thirteen digits. |
441134960123 | rejected | No plus sign. |
+44 113 496 0123 | rejected | Spaces: normalise first. |
+44(0)1134960123 | rejected | The (0) and brackets must be removed. |
+0441134960123 | rejected | A country code never starts with 0. |
+4411349601234567 | rejected | Sixteen digits, one more than E.164 allows. |
+1 | rejected | Too short to be a number. |
Normalise first, then check
People type phone numbers with spaces, hyphens, dots and brackets, and UK numbers often appear as +44 (0)113 …, where the bracketed 0 is dialled only from inside the country. Remove all of that before you validate, and keep what the user typed only for display:
const E164 = /^\+[1-9][0-9]{1,14}$/;
// Drop a "(0)" written after the country code, then spaces, brackets, dots and hyphens.
const normalisePhone = (input) => input.replace(/\(0\)/g, '').replace(/[\s().-]/g, '');
const n = normalisePhone('+44 (0)113 496 0123');
console.log(n, E164.test(n)); // → +441134960123 true
console.log(normalisePhone('(0113) 496-0123')); // → 01134960123import re
E164 = re.compile(r'\+[1-9][0-9]{1,14}')
def normalise_phone(text):
# Drop a "(0)" written after the country code, then spaces, brackets, dots and hyphens.
return re.sub(r'[\s().-]', '', text.replace('(0)', ''))
n = normalise_phone('+44 (0)113 496 0123')
print(n, bool(E164.fullmatch(n))) # → +441134960123 True
print(normalise_phone('(0113) 496-0123')) # → 01134960123A leading 00 is the international call prefix in the UK and much of Europe, so 0044… means +44…; convert it if your users write numbers that way. In North America the prefix is 011, which is why you should not try to guess.
UK numbers
Ofcom, which runs the UK numbering plan, says that UK numbers almost all have ten digits after the leading 0, but that a number of geographic areas still use nine-digit numbers (see Ofcom: telecoms numbering). After normalising, this pattern accepts a 0 or +44 followed by nine or ten digits that do not start with 0:
/^(?:\+44|0)[1-9][0-9]{8,9}$/| Input | Result | Why |
|---|---|---|
01134960123 | matches | A Leeds number in national form. |
+441134960123 | matches | The same number in international form. |
07700900123 | matches | Mobiles have the same length. |
0123456789 | matches | Nine digits after the 0 are accepted too, for the areas that still have nine-digit numbers. |
+4401134960123 | rejected | The 0 must be dropped after +44. |
00441134960123 | rejected | The 00 international prefix: convert it to + first. |
011349601 | rejected | Too short. |
011349601234 | rejected | Too long. |
01134 960123 | rejected | A space: normalise first. |
For numbers starting 07, the range used for mobiles:
/^(?:\+44|0)7[0-9]{9}$/| Input | Result | Why |
|---|---|---|
07700900123 | matches | National form. |
+447700900123 | matches | International form. |
01134960123 | rejected | A landline. |
0770090012 | rejected | One digit short. |
The 07 range is not only mobiles: 070 numbers, for example, are personal numbers that forward to another phone, so check with a numbering library if the difference matters. The UK examples on this page use the Leeds range 0113 496 0000 to 0999, which Ofcom keeps for TV and radio drama so that it is never given to a real customer.
Why a library beats a regex here
Every country has its own lengths and prefixes, and they change. A single pattern can only check that a string looks like a phone number; it cannot tell a real German mobile from a random string of the right length. Google's libphonenumber holds the rules for every country, parses numbers in national or international form, formats them for display and tells you the number type. It has ports for JavaScript, and Python has phonenumbers, a port of the same data.
In HTML, use <input type="tel" autocomplete="tel">. The browser shows a phone keypad on mobile devices but does not check the format, because the HTML standard leaves phone formats to the site; that is the job of the pattern or the library on your side. The only way to know that a number works is to call it or send it a code.
In JavaScript, Python, PHP and C#
JavaScript
const re = /^\+[1-9][0-9]{1,14}$/;
console.log(re.test('+441134960123')); // → true
console.log(re.test('441134960123')); // → false
Python
import re
pattern = re.compile(r'\+[1-9][0-9]{1,14}')
print(bool(pattern.fullmatch('+441134960123'))) # → True
print(bool(pattern.fullmatch('441134960123'))) # → False
PHP
<?php
$pattern = '/^\+[1-9][0-9]{1,14}$/D';
echo preg_match($pattern, '+441134960123'), "\n"; // → 1
echo preg_match($pattern, '441134960123'), "\n"; // → 0
C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^\+[1-9][0-9]{1,14}\z");
Console.WriteLine(pattern.IsMatch("+441134960123")); // → True
Console.WriteLine(pattern.IsMatch("441134960123")); // → FalseEach version checks the whole string. JavaScript's $ only matches at the very end, but Python, PHP and .NET also let $ match just before a final line break, so "abc\n" could slip through. The Python version uses re.fullmatch (so the ^ and $ are dropped), PHP adds the D modifier, and C# ends with \z.
The JavaScript, Python and C# examples are run before each update and their output is compared with the comments. PHP is not installed on our build machine, so the PHP version is checked against the PCRE pattern modifier documentation, and its string literal is checked to hand PHP exactly the pattern tested here.
Questions
What is the regex for an international phone number?
For numbers in E.164 form, ^\+[1-9][0-9]{1,14}$: a plus sign, a first digit from 1 to 9 and up to 14 more digits. Remove spaces and punctuation before checking.
How many digits can a phone number have?
E.164 allows at most 15 digits, including the country code but not the plus sign or any international call prefix.
Should I store phone numbers as numbers?
No. Store them as text in E.164 form, such as +441134960123. As a number, the plus sign and any leading zero are lost.