JavaScript / ECMAScript

International Phone (E.164) in JS

Validate phone numbers in ITU-T E.164 international format: a + sign followed by 2–15 digits, first digit non-zero.

Try it in the JS tester →

Pattern

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

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^\\+[1-9]\\d{1,14}$", "");
const input = "+14155552671";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

^ anchors the start. \+ matches the required leading plus sign. [1-9] ensures the country code starts with a non-zero digit. \d{1,14} allows 1 to 14 additional digits for a total of 2–15 digits after the +, per E.164 spec. $ anchors the end.

Examples

Input

+14155552671

Matches

  • +14155552671

Input

+442071838750

Matches

  • +442071838750

Input

14155552671

No match

Same pattern, other engines

← Back to International Phone (E.164) overview (all engines)