Phone number regex by country

Pick a country, mobile numbers only or all number types, and E.164, national format or both. The generator builds a regex from libphonenumber's numbering-plan data, runs it on the country's official example number written right and wrong, and gives ready code for JavaScript, Python, PHP, Java and Go. A regex checks a number's shape, not whether it exists: why that matters.

Free · no sign-up · runs in your browser, nothing is uploaded

Numbers
Format

+44 · trunk prefix 0

Regex

^\+44(?:7(?:457[0-57-9]|700[01]|911[028])\d{5}|7(?:[1-3]\d\d|4(?:[0-46-9]\d|5[0-689])|5(?:0[0-8]|[13-9]\d|2[0-35-9])|7(?:0[1-9]|[1-7]\d|8[02-9]|9[0-689])|8(?:[014-9]\d|[23][0-8])|9(?:[024-9]\d|1[02-9]|3[0-689]))\d{6})$

218 characters

const PHONE = /^\+44(?:7(?:457[0-57-9]|700[01]|911[028])\d{5}|7(?:[1-3]\d\d|4(?:[0-46-9]\d|5[0-689])|5(?:0[0-8]|[13-9]\d|2[0-35-9])|7(?:0[1-9]|[1-7]\d|8[02-9]|9[0-689])|8(?:[014-9]\d|[23][0-8])|9(?:[024-9]\d|1[02-9]|3[0-689]))\d{6})$/;
PHONE.test("+447400123456"); // true or false

Test strings (the official example number of United Kingdom)

StringShouldRegex
+447400123456passmatchesE.164 form of the example number
07400123456failno matchNational form: not allowed with E.164 only
07400 123456failno matchNational form with spaces: not allowed with E.164 only
+44740012345failno matchOne digit short
+4474001234561failno matchOne digit too many
00447400123456failno match00 instead of +: write the international form with +

Tested in your browser

A regex checks a number's shape, not whether it exists. A number can match and still be unassigned, switched off or ported to another network. Why an E.164 regex is not enough.

Runs entirely in your browser. Nothing you type, paste or upload is sent to MobileValidate or anyone else, and nothing is stored. The page counts one anonymous "tool used" event per visit (no numbers, no text), and sends nothing at all when your browser asks not to be tracked.

A regex can't tell you if a number is live

A number with the right shape can be unassigned, switched off or ported. Check whether numbers are live and which network they are on before you rely on them.

How it works

The patterns come from libphonenumber (version 1.13.15), the open-source numbering-plan database most phone apps use, taken when the site is built. For each of 238 countries there is a pattern for every valid national number (all types) and one for mobile numbers. Where mobile and fixed lines share ranges, as in the United States and Canada, the mobile pattern is the shared one. Where a national regulator's published numbering plan assigns ranges the library does not list yet, the pattern follows the regulator, as our API does: Kuwait's mobile regex accepts every 8-digit number starting with 41, 5, 6 or 9, as in the CITRA plan of 2023-08-10.

E.164 is +, the country code and the national number with no spaces, so that regex is strict. National adds the optional trunk prefix (0 in most countries) and, if you tick it, an optional space or dash between any two digits, never at the start or end. Both accepts either form.

The test strings are the country's official example number from the same data: in E.164, in national form, one digit short, one digit long and with 00 instead of +. The page runs the regex on each in your browser and shows what should pass and what does, and you can try your own string.

The regex uses no lookarounds or back-references, so the same pattern works in JavaScript, Python, PHP (PCRE), Java and Go (RE2). The Python snippet adds re.ASCII so \d matches only 0 to 9.

Last updated

What a regex cannot tell you

  • Whether the number exists. A number can match every rule of its country and still be unassigned, disconnected or recycled. Only the network knows: an HLR lookup asks it.
  • Which network it is on. Ranges say where a number started; ported numbers keep their range. A carrier lookup returns today's network and line type.
  • Every way people write numbers. Brackets, dots, extensions and old prefixes need normalising first. For user input, parse with a library and store E.164; see why a regex is not enough.

Frequently asked questions

What is the regex for an E.164 phone number?

The generic one is ^\+[1-9]\d{1,14}$: a +, a first digit that is not 0, and at most 15 digits. It accepts many numbers no country assigns. A country regex from this page is stricter: for the United Kingdom it accepts only the lengths and leading digits UK numbers use. See the E.164 guide.

Can a regex check whether a phone number is real?

No. A regex checks the shape of a number: its length and leading digits. Whether it is assigned, switched on or ported is only known to the network. An HLR lookup answers whether a number is live; the phone number validator adds the number type and formats.

Why not use one regex for every country?

Because the rules differ: UK mobiles have 10 national digits starting with 7, German mobiles 10 or 11 starting with 15, 16 or 17, Indian mobiles 10 starting with 6 to 9. One regex for all of them is either so loose it accepts nonsense or so strict it rejects real numbers.

Should I validate phone numbers with a regex or a library?

For user input, a library such as libphonenumber: it handles the formats people type, the trunk prefix and number types, and is updated when plans change. A regex is useful where you cannot add a library, such as a database constraint, a form pattern or a configuration file. Our guides show both in JavaScript and Python.

Why is national format not offered for Argentina?

In Argentina, mobile numbers are written nationally with a 15 after the area code but carry a 9 after +54 internationally, so the national form is not a simple prefix of the international one. A national regex built from the plan would reject how people really write them, so for Argentina the generator gives E.164 only.

How current are the patterns?

They come from libphonenumber (version 1.13.15), taken when the site was built. Numbering plans change several times a year, so a regex copied today can reject new ranges later. Re-generate it from time to time, or validate with the library itself.