Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for US phone number
Regex pattern · validation

Regex for US phone number

Regex for US phone number: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$/ as a US phone number regex. It matches "(555) 123-4567" and "555-123-4567", and rejects "123-456-7890" and "555-1234". Parentheses are not checked for balance, so "(555 123-4567" also passes.

Last updated · Maintained by FreeAIToolz · How we test

/^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$/
  • (555) 123-4567matches
  • 555-123-4567matches
  • +1 555 123 4567matches
  • 5551234567matches
  • 555.123.4567matches
  • 123-456-7890no match
  • 555-1234no match
  • 555-123-45678no match
  • +44 20 7183 8750no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
(?:\+?1[-.\s]?)?optional country code 1 or +1
\(?([2-9]\d{2})\)?area code (cannot start with 0 or 1), optional parentheses
[-.\s]?optional separator
(\d{3})exchange
(\d{4})$line number

Examples

InputResult
(555) 123-4567✓ Matches
555-123-4567✓ Matches
+1 555 123 4567✓ Matches
5551234567✓ Matches
555.123.4567✓ Matches
123-456-7890✗ No match
555-1234✗ No match
555-123-45678✗ No match
+44 20 7183 8750✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Parentheses are not checked for balance, so "(555 123-4567" also passes. For international numbers, store E.164 and validate with a library such as libphonenumber.

When to use this pattern

US and Canada (NANP) phone fields in forms and CRMs. Normalise to +1XXXXXXXXXX before storing.

Use it in your language

JavaScript

const re = /^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^(?:\\+?1[-.\\s]?)?\\(?([2-9]\\d{2})\\)?[-.\\s]?(\\d{3})[-.\\s]?(\\d{4})$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^(?:\\+?1[-.\\s]?)?\\(?([2-9]\\d{2})\\)?[-.\\s]?(\\d{3})[-.\\s]?(\\d{4})$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for US phone number?
/^(?:\+?1[-.\s]?)?\(?([2-9]\d{2})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})$/. Parentheses are not checked for balance, so "(555 123-4567" also passes. For international numbers, store E.164 and validate with a library such as libphonenumber.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abc(555) 123-4567xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.