Regex for an E.164 phone number

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

E.164 is the ITU’s format for international phone numbers: a +, the country code, then the national number, with no spaces or punctuation and at most 15 digits in all. Country codes never start with 0, so the first digit is [1-9], and up to 14 more digits follow. It’s the format SMS and voice APIs such as Twilio’s expect.

What it accepts

The tester below checks one number per line with g and m; for a single value, drop both flags.

+14155552671         matches: United States
+442071838750        matches: United Kingdom
+4915123456789       matches: Germany
+380441234567        matches: Ukraine
14155552671          no: no plus sign
+1 415 555 2671      no: spaces
+0123456789          no: country codes don't start with 0
+1234567890123456    no: 16 digits

What it can’t tell you

The pattern checks the outline only. +12 passes, and so does a number in a country code nobody has been given. Each country sets its own lengths and prefixes, and a regex that knew them all would be enormous and out of date within a year. For real validation, use Google’s libphonenumber, or its JavaScript port libphonenumber-js, which knows every country’s rules and can tell a mobile number from a landline.

Accepting what people type

People write +1 (415) 555-2671, not +14155552671. Strip the formatting first, then check:

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

function toE164(typed) {
  const compact = typed.replace(/[\s().-]/g, '');
  return E164.test(compact) ? compact : null;
}

toE164('+1 (415) 555-2671'); // '+14155552671'
toE164('(415) 555-2671');    // null: no country code

A number without a country code can’t be turned into E.164 by a regex: 415 555 2671 is American only if you already know the caller is in the United States. Ask for the country separately, or default it from the visitor’s region, and let a library add the code.

Try it in the Regex Tester

Flags

4 matches

Matches

#MatchAtGroups
1+141555526710–12none
2+44207183875013–26none
3+491512345678927–41none
4+38044123456742–55none

What the pattern means

  • ^The start of a line
  • \+The character "+"
  • [1-9]One of: 1–9
  • \d{1,14}A digit (0–9), 1 to 14 times, as many times as possible (greedy)
  • $The end of a line
  • g global: Find every match, not just the first. exec() and test() carry on from lastIndex.
  • m multiline: ^ and $ match at the start and end of each line, not just of the whole string.

Runs in your browser. Nothing you enter is sent anywhere.