Regex and cron

Regex for Phone Numbers (E.164 Format)

Check that a phone number is stored in the international E.164 format that SMS and calling APIs expect.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.

Pattern

/^\+[1-9]\d{1,14}$/

Regular expression

JavaScript syntax, run by your browser's own engine in a background worker. Press / anywhere to jump here.
Reset to the original pattern and examplesShow cheat sheet: click any token to insert itCopy pattern
Find every match instead of stopping at the first. Needed for matchAll() and for replacing all occurrences.Case-insensitive: /abc/i also matches "ABC" and "aBc".^ and $ match at the start and end of every line, not just the whole string. Use it to test one value per line.Lets . match line breaks too. Without it, . stops at \n and \r.Treats the pattern as Unicode code points: enables \p{…} property escapes and \u{…}, makes emoji count as one character, and rejects sloppy escapes.Only matches starting exactly at lastIndex (position 0 here), never further along. Useful for tokenizers that consume input piece by piece.Records the start and end index of every capture group (match.indices). The tester always shows group positions, so this only changes your code.The upgraded unicode mode (ES2024): set operations like [\p{L}--[a-z]] and [A&&B], string properties like \p{RGI_Emoji}. Cannot be combined with u.
4 matches4 matches

Test string

Matches are highlighted as you type, in alternating colors. Click inside a match (or hover its row below) to color its capture groups.
4 matchesClear test string

Explanation

Every part of the pattern in plain English. Hover a row to highlight that part of the pattern.
Copy explanation

Loading the explainer…

Every match with its position and capture groups.Preview a replacement with $1, $<name> and $& references, then copy the result.Copy a ready-to-run snippet for JavaScript, Python, Go, C#, PHP or Dart.

Matches

Named groups are shown by name. undefined means the group did not take part in that match.
Copy matches as JSONDownload matches.csv
#MatchPosition
1+141555526710–12
2+44207183875013–26
3+91987654321027–40
4+551198765432141–55

Need a secure web app built around this? Talk to our team

Quick answer

The regex for an E.164 phone number is ^\+[1-9]\d{1,14}$: a plus sign, a first digit from 1 to 9 (country codes never start with 0), then up to 14 more digits for at most 15 in total. It matches +14155552671 and +442071838750. Use it on normalized numbers: strip spaces, dashes and brackets first, or better, parse user input with libphonenumber.

  • Tested examples
  • Token-by-token breakdown
  • Code in 5 languages
  • Live tester

How to use the phone number (E.164) regex

  1. 1Copy the pattern with Copy pattern in the tester, or take a ready-made snippet for your language from the code section below.
  2. 2Check the sample lines in Test string: every line the phone number (E.164) regex accepts is highlighted, rejected lines stay plain.
  3. 3Paste your own values one per line to see which pass, and read Explanation for what each part of the pattern does.
  4. 4Open the Code tab for JavaScript, Python, Go, C#, PHP or Dart with the pattern translated and escaped.
  5. 5Validate again on the server: client-side checks give users quick feedback, not security.

How does the phone number (E.164) regex work?

Read it left to right. Each piece below matches one part of the input:

  • ^ Start of the string.
  • \+ A literal plus sign. E.164 numbers always carry it when written for machines.
  • [1-9] The first digit of the country code. No country code starts with 0.
  • \d{1,14} 1 to 14 more digits: the rest of the country code plus the national number. E.164 caps the total at 15 digits.
  • $ End of the string: no extensions, spaces or punctuation.

Which strings does the phone number (E.164) regex match?

The whole input must match, from the first character to the last. Every row below is checked against the pattern by our automated test suite before each release.

InputMatches?Why
+14155552671YesUnited States: country code 1, then a 10-digit number.
+442071838750YesUnited Kingdom: country code 44, national number without its leading 0.
+919876543210YesIndia: country code 91 and a 10-digit mobile number.
+5511987654321YesBrazil: 55, area code 11 and a 9-digit mobile.
14155552671NoMissing the leading plus sign.
+0123456789NoCountry codes never start with 0.
+1 415 555 2671NoSpaces are formatting, not part of E.164. Strip them first.
+1-415-555-2671NoDashes too.
+1234567890123456No16 digits: one more than E.164 allows.
+1NoA country code alone is not a phone number.

Why not write a regex for every phone format?

Because there are hundreds. Lengths, area codes and mobile prefixes differ by country and change over time: a UK mobile is 07… nationally but +447… internationally, Germany has variable-length numbers, and the North American plan forbids area codes that start with 0 or 1. A regex that tracks all of that is a maintenance project.

The robust approach has three steps:

  1. Accept loose input. Let people type spaces, dashes, dots and brackets the way they are used to.
  2. Parse and normalize with Google's libphonenumber (ports exist for JavaScript, Python, Go, C#, PHP and Dart). It knows each country's rules and returns the E.164 form.
  3. Store and validate E.164 with the pattern on this page. Twilio and AWS SNS expect E.164, and most other messaging APIs accept it.

What does a looser pattern for typed input look like?

If you cannot use a library, a forgiving first pass accepts common punctuation and then counts digits:

^\+?[0-9 ()\-.]{7,20}$

Then remove everything except digits and the leading plus, and check the result against the E.164 pattern. Splitting the job like this keeps each regex simple and gives users clear error messages: "remove the letters" is easier to act on than "invalid phone number".

The E.164 recommendation itself is short and worth a read: it is the source of the 15-digit limit.

How do I use the phone number (E.164) regex in JavaScript, Python, Go, C# and PHP?

The pattern is translated for each engine rather than pasted as is: named groups, anchors, escapes, shorthand classes and flags are adjusted so each snippet behaves as closely to the JavaScript version as its engine allows. Differences that remain (Go's RE2 has no lookarounds or backreferences, for example) are called out under each one. The Code tab in the tester above also exports Dart, and updates as you edit the pattern.

JavaScript and TypeScript

const regex = /^\+[1-9]\d{1,14}$/;

function isValid(value) {
  return regex.test(value);
}

console.log(isValid("+14155552671"));

Python

import re

pattern = re.compile(r"^\+[1-9][0-9]{1,14}\Z")

def is_valid(value: str) -> bool:
    return pattern.search(value) is not None

print(is_valid("+14155552671"))
  • \d and \w are written as [0-9] and [A-Za-z0-9_] because in Python they also match digits and letters from other scripts.
  • JavaScript's $ only matches at the very end of the string. Python's $ also matches before a trailing newline, so the pattern uses \Z instead.

Go

package main

import (
	"fmt"
	"regexp"
)

func main() {
	re := regexp.MustCompile(`^\+[1-9]\d{1,14}$`)
	fmt.Println(re.MatchString("+14155552671"))
}

C#

using System;
using System.Text.RegularExpressions;

// The timeout stops a pathological input from hanging the thread (ReDoS).
var regex = new Regex(@"^\+[1-9][0-9]{1,14}\z", RegexOptions.None, TimeSpan.FromSeconds(1));
Console.WriteLine(regex.IsMatch("+14155552671"));
  • \d and \w are written as [0-9] and [A-Za-z0-9_] because in .NET they also match digits and letters from other scripts.
  • JavaScript's $ only matches at the very end of the string. .NET's $ also matches before a trailing newline, so the pattern uses \z instead.

PHP

<?php

$pattern = '/^\+[1-9]\d{1,14}$/D';

function isValid(string $value, string $pattern): bool
{
    return preg_match($pattern, $value) === 1;
}

var_dump(isValid('+14155552671', $pattern));
  • The D modifier makes $ match only at the very end, like JavaScript (PCRE's $ also matches before a trailing newline).

Browse all 25 patterns in the regex pattern library, or build your own in the regex tester.

Frequently asked questions

E.164 is the ITU's international numbering format: a plus sign, a country code of one to three digits and the national number, with no spaces or punctuation, at most 15 digits in total. For example, +14155552671 for a US number.
Use a parsing library such as libphonenumber. It knows the valid lengths and prefixes for every country and converts what users type into E.164. Use the regex on this page only to check the normalized result.
E.164 contains digits only. Spaces, dashes and brackets are display formatting, so remove them before validating, or validate typed input with a looser pattern and normalize afterwards.
No. A regex only checks the shape. To confirm a number exists and belongs to the user, send a one-time code by SMS or a call.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Building something bigger than a quick fix?

Auth, payments, dashboards and security are where web apps get hard. We have shipped them many times. Share your idea and we will map out a realistic plan and estimate, free and with no obligation.

More free tools

See all tools

Regex Tester

Test regex live with highlighted matches, plain-English explanations and code export.

Open tool

Cron Expression Generator

New

Build and explain cron schedules, see the next runs in any time zone, copy platform snippets.

Open tool

SQL Formatter

Beautify or minify SQL in 12 dialects, with keyword case, indent and line:column errors.

Open tool

cURL to Python Converter

New

Convert cURL commands into Python requests or httpx code with params, json, files and auth.

Open tool

cURL to Fetch Converter

New

Turn any cURL command into JavaScript fetch() code with headers, JSON, forms and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool