Contact
International Phone Number (E.164) Regex
E.164 is the international numbering format used by SMS gateways, VoIP platforms and most phone verification services. A number is written as a plus sign followed by the country code and subscriber number, with no spaces or punctuation and at most fifteen digits. This pattern enforces exactly that, including the rule that the first digit cannot be zero. It is ideal for storing phone numbers in a canonical form. The honest limit is that it cannot check whether a country code exists or whether the number length is right for that particular country.
Pattern (JavaScript)
/^\+[1-9][0-9]{7,14}$/Starts at the start of the line/string, then the character "+", then one of the characters 1-9, then a digit, between 7 and 14 times, then the end of the line/string.
Limit: Checks the E.164 format only; it cannot tell whether the number is assigned or reachable.
Examples
Matches
- ✓ +14155550100
- ✓ +442079460018
- ✓ +971501234567
Does not match
- ✗ 14155550100
- ✗ +0123456789
- ✗ +1 415 555 0100
Try it
0 matches (JavaScript engine)
+14155550100
+442079460018
+971501234567
14155550100
+0123456789
+1 415 555 0100Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^\+[1-9][0-9]{7,14}$/g;
const text = "+14155550100";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^\+[1-9][0-9]{7,14}$')
text = '+14155550100'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^\+[1-9][0-9]{7,14}$/';
$text = '+14155550100';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^\\+[1-9][0-9]{7,14}$");
String text = "+14155550100";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^\+[1-9][0-9]{7,14}$`)
text := "+14155550100"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^\+[1-9][0-9]{7,14}$");
var text = "+14155550100";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^\+[1-9][0-9]{7,14}$").unwrap();
let text = "+14155550100";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^\+[1-9][0-9]{7,14}$/
text = '+14155550100'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why are spaces and dashes not allowed?
- E.164 is a storage format with digits only after the plus sign. Accept friendly input in your form, strip everything except digits and the leading plus, and then test the cleaned value against this pattern.
- Why is the minimum eight digits?
- Very short international numbers are rare, so requiring at least eight digits after the plus sign rejects many incomplete entries. You can lower the minimum if you serve countries with shorter numbers.
- Can I tell the country from the number?
- Only with a country code table, because codes vary from one to three digits. A library such as libphonenumber is the reliable way to split a number into country code and national number.