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.