WORKED EXAMPLE / ECMASCRIPT

US phone number regex

A North American-style phone check with an optional +1 country code, paired area-code parentheses, and common separators.

Pattern

^(?:\+1[ .-]?)?(?:\(([2-9]\d{2})\)|([2-9]\d{2}))[ .-]?([2-9]\d{2})[ .-]?(\d{4})$
Flavor
JavaScript (ECMAScript)
Flags
Flags: none

What it does

This pattern recognizes ten-digit US-style numbers while requiring area and exchange codes to begin with 2–9. Parentheses are accepted only as a balanced pair around the area code.

Token-by-token explanation

  1. ^

    Starts matching at the beginning of the input.

  2. (?:\+1[ .-]?)?

    Optionally accepts the literal +1 country code followed by one optional space, dot, or hyphen.

  3. (?:\(([2-9]\d{2})\)|([2-9]\d{2}))

    Accepts a three-digit area code either inside balanced parentheses or without parentheses; its first digit must be 2–9.

  4. [ .-]?

    Allows one optional separator after the area code.

  5. ([2-9]\d{2})

    Captures the three-digit exchange code and prevents it from beginning with 0 or 1.

  6. [ .-]?

    Allows one optional separator before the subscriber number.

  7. (\d{4})

    Captures the final four-digit subscriber number.

  8. $

    Stops matching at the end of the input.

Test strings

Matches

  • +1 (212) 555-0198
  • 415.867.5309

Does not match

  • +44 20 7946 0958
  • (112) 555-0198

Common mistakes

  • Making opening and closing parentheses independently optional, which accepts unbalanced phone numbers.
  • Stripping a leading country code without first knowing which numbering plan the user selected.

Limitations

  • It models a US/NANP-style shape only; it does not support international numbering plans, extensions, short codes, or prove that an assigned number is reachable.