Phone number regex

Regex patterns for phone numbers: North American (NANP) with optional formatting, and international E.164. Tested examples and caveats.

Pattern
/^(?:\+?1[-. ]?)?\(?([2-9][0-9]{2})\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/

Matches

  • (415) 555-2671
  • 415.555.2671
  • +1 415 555 2671

Doesn't match

  • 555-2671
  • (115) 555-2671
  • 415-555-26711

Alternative: International E.164 (digits only, with +)

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

Notes

  • The NANP pattern enforces that area codes and exchanges cannot start with 0 or 1.
  • E.164 is the storage format recommended by the ITU: a + followed by up to 15 digits and no spaces. Normalise user input to it before saving.
  • For real validation across countries, use a library such as Google's libphonenumber — numbering plans change.

Code

JavaScript

const re = /^(?:\+?1[-. ]?)?\(?([2-9][0-9]{2})\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/;
re.test(value); // true or false

Python

import re

bool(re.fullmatch(r'(?:\+?1[-. ]?)?\(?([2-9][0-9]{2})\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})', value))

Try it on your own input

The live tester adds the g and m flags so every line is checked separately.

Questions

How do I strip formatting before validating?

Remove everything except digits and a leading plus: value.replace(/[^\d+]/g, ""), then test against the E.164 pattern.

More patterns

Email regexURL regexIP address regexDate regexTime regex (24-hour and 12-hour)UUID regexHex color regexPassword regex