New blogMaking an AI Agent You Can Trust With Money

★ Identity & contact · regex

Regex for E.164 Phone Number

E.164 is the ITU format for international phone numbers and the one SMS APIs expect: a plus sign, a country code that doesn't start with 0, and at most 15 digits in total, with no spaces or punctuation.

  • Runs in your browser
  • No signup

Try the e.164 phone number pattern

Read it in plain English (best-effort)

  • ^start of a line
  • +the character '+'
  • [1-9]one character from: 1–9
  • [0-9]one character from: 0–9
  • {6,14}between 6 and 14 of the previous
  • $end of a line

One sample per line works well with the m flag on anchored patterns.

Waiting for a pattern
01

The pattern, piece by piece

/^\+[1-9][0-9]{6,14}$/
Pattern explanation
PartWhat it does
^\+a literal plus sign
[1-9]country codes never start with 0
[0-9]{6,14}the rest: 7 to 15 digits in total
$no spaces or punctuation anywhere
02

What it accepts and rejects

Every sample below is checked automatically in JavaScript and Python. The tester above is preloaded with all of them, one per line.

Should match
Should match
+14155552671✓
+919876543210✓
+442079460958✓
+81312345678✓
+61412345678✓
+4915112345678✓
Should not match
Should not match
14155552671✗
+0123456789✗
+1 415 555 2671✗
+1234✗
+1234567890123456✗
+91-9876543210✗
03

Copy it into your code

RE2-safeNo lookarounds or backreferences, so the same pattern works in Go's RE2 engine and in Rust's regex crate.

const e164PhoneRe = /^\+[1-9][0-9]{6,14}$/;

export function isValidE164Phone(value) {
  return e164PhoneRe.test(value.trim());
}
04

When not to use regex for this

The regex can't tell whether +91 is followed by a valid Indian number length. libphonenumber knows every country's rules; use it to parse what users type and store the E.164 string it returns.

05

Questions engineers actually ask

Why no spaces or dashes?
E.164 is a storage and API format, not a display format. Strip formatting before validating.
What is the minimum length?
This pattern requires 7 digits, which excludes obvious junk. Some small territories have shorter numbers; libphonenumber handles those exactly.
What is catastrophic backtracking?
Some patterns, usually nested quantifiers like (a+)+, make a backtracking engine try an exponential number of paths on input that almost matches. The tester stops any run after 300ms, so a bad pattern can't freeze your tab. In production, that same pattern can take down a server (a ReDoS attack).
06

Sources

Formats were checked on 8 November 2026. Rules change; the official issuer wins if it disagrees.

07

More identity & contact patterns

08

More from the workbench

Fine print

Tools: on the house.
Engineer: by the hour.

The regex was free. Code that doesn't need one is the upgrade: typed schemas, validated once at the edge, trusted everywhere after.

I'm Himanshu, an AI and full-stack engineer. I build MVPs, AI agents and the growth plumbing around them for early-stage startups.