Regex patterns/Validation

E.164 phone number

The international format: a plus, a non-zero country code, then digits.

/^\+[1-9]\d{7,14}$/
Open it in Rex

The problem

Check that a phone number is in international E.164 form before storing or sending it.

How it reads

start\+[1-9]\drepeatend

Follow the line from left to right — every path you can trace is a string this pattern matches.

  1. ^\+[1-9]\d{7,14}$In order:
  2. ^The start of the text (or of a line with the m flag)
  3. \+The character "+"
  4. [1-9]Any one of: "1" to "9"
  5. \d{7,14}A digit, between 7 and 14 times, as many as possible
  6. $The end of the text (or of a line with the m flag)

Matches

  • +6421234567
  • +14155552671

Does not match

  • 021 234 567
  • +0123456789
  • 12345
  • +12

Where it bites

  • This validates the normalised form only. Strip spaces, dashes and brackets first — trying to match every way a human writes a phone number is a losing game.
  • A country code never starts with zero, which is what [1-9] enforces.
  • E.164 allows up to 15 digits in total including the country code; the {7,14} here follows the plus-one first digit.

More validation patterns