JavaScript / ECMAScript

International Phone Number (Loose) in JS

Match international phone numbers in a variety of loose formats including country codes, area codes, and separators.

Try it in the JS tester →

Pattern

regexJS
\+?[1-9]\d{0,3}[\s.\-]?(?:\(?\d{1,4}\)?[\s.\-]?){2,4}\d{1,9}   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\+?[1-9]\\d{0,3}[\\s.\\-]?(?:\\(?\\d{1,4}\\)?[\\s.\\-]?){2,4}\\d{1,9}", "g");
const input = "+1 (415) 555-2671";
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

\+? optionally matches a leading +. [1-9]\d{0,3} matches 1–4 digit country/area code. The repeating group (?:\(?\d{1,4}\)?[\s.\-]?){2,4} matches digit groups with optional parentheses and separators. Ends with 1–9 final digits.

Examples

Input

+1 (415) 555-2671

Matches

  • +1 (415) 555-2671

Input

+44 20 7183 8750

Matches

  • +44 20 7183 8750

Input

not a phone

No match

Same pattern, other engines

← Back to International Phone Number (Loose) overview (all engines)