Utilo

E.164 Phone Regular Expression – Free, Online, Private

Matches a leading plus, a non-zero country code, and 8 to 15 digits in total.

Tester
Sample
Matches (2)
  • +14155552671
  • +442071838750

The pattern

E.164 numbers are a plus followed by digits, with no spaces, and at most 15 digits. This pattern requires the plus, forbids a leading zero after it, and requires 8 to 15 digits in total. +14155552671 and +442071838750 match. A national number without a plus does not. A number that starts +0 does not, because country codes do not start with 0. The pattern does not check that the country code is assigned.

The source is \+[1-9]\d{7,14}. No flags are set. The match is case-sensitive, and ^ or $ mean the start and end of the whole input. Add m yourself in the tester if you paste several lines. The box under the title is a tester with this pattern and the sample already filled in. Edit either one. Nothing you type is uploaded. The same tester, without a preset, is the regex tool.

How to read it

\+ is a literal plus. [1-9] is the first digit. \d{7,14} is seven to fourteen more digits. One plus that range is eight to fifteen digits, which is the E.164 maximum and a minimum that rejects very short strings. Spaces, dashes, and parentheses are not allowed. Strip them before testing if your input is a human-formatted number. The pattern is not anchored. In a paragraph it will find the number. On a form, add ^ and $.

What it will not do

The minimum length will reject some short national numbers even when they are written with a country code, if the total is under eight digits. Raise or lower the quantifier if you have a real list of the lengths you accept. The pattern does not dial anything and does not store the number. It is a shape check. Extensions, pauses, and the visual separators people type into a notes field are out of scope. Remove them first.

A match is not a parsed value. An email pattern does not send mail, a UUID pattern does not allocate an id, and a password pattern does not store a password. When the next step needs a real parser, use one: the URL constructor, a date library, a semver library, or the converters on this site. The expression is the part you can see.

JavaScript, Python, and Go

The JavaScript snippet uses the RegExp constructor so the source does not have to be escaped for a literal slash. The Python snippet uses a normal string with the same escapes JSON would emit, which keeps \d as a regex digit class. Go's snippet uses a raw string. If the pattern contains a lookahead, the Go snippet says so and does not call MustCompile, because RE2 would reject it at runtime.

JavaScriptconst re = new RegExp("\\+[1-9]\\d{7,14}", "");
const found = text.match(re);
console.log(found ? found[0] : "no match");
Pythonimport re

pattern = re.compile("\\+[1-9]\\d{7,14}")
found = pattern.search(text)
print(found.group(0) if found else "no match")
Gopackage main

import (
	"fmt"
	"regexp"
)

func main() {
	text := ""
	re := regexp.MustCompile(`\+[1-9]\d{7,14}`)
	fmt.Println(re.FindString(text))
}

Frequently asked questions

Why is the plus required?

E.164's international form starts with +. Without it, the digits are a national number and the country is ambiguous.

Are spaces allowed?

No. Remove spaces, dashes, and parentheses before testing.

What is the longest match?

Fifteen digits after the plus sign is not allowed. The total of digits is 8 to 15.

Does +0123… match?

No. The first digit cannot be 0.