Regex for US phone number

Use /^(?:\+1[-. ]?)?\(?([2-9]\d{2})\)?[-. ]?(\d{3})[-. ]?(\d{4})$/ to check that a whole string is a valid for US phone number. Every example below is tested against the pattern, and you can open it in the Regex Tester with the samples preloaded.

Updated

/^(?:\+1[-. ]?)?\(?([2-9]\d{2})\)?[-. ]?(\d{3})[-. ]?(\d{4})$/
Open in Regex Tester
InputResultGroups
(212) 555-0123✓ Match212 555 0123
212-555-0123✓ Match212 555 0123
+1 415.555.0199✓ Match415 555 0199
4155550199✓ Match415 555 0199
123-456-7890✗ No match
555-1234✗ No match
(212) 555-01234✗ No match
+44 20 7183 8750✗ No match

How the pattern works

PartMeaning
(?:\+1[-. ]?)?Optional +1 country code, followed by an optional separator
\(?([2-9]\d{2})\)?Area code (group 1), optionally in parentheses; it can’t start with 0 or 1
[-. ]?Optional dash, dot or space
(\d{3})Exchange (group 2)
(\d{4})Line number (group 3)

Code examples

JavaScript

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

Python

import re

bool(re.fullmatch(r'(?:\+1[-. ]?)?\(?([2-9]\d{2})\)?[-. ]?(\d{3})[-. ]?(\d{4})', value))

PHP

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

Notes and limitations

The three groups let you normalize any accepted format, for example to ($1) $2-$3. For international numbers, store them in E.164 format and use a library such as libphonenumber for real validation.

Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool

Frequently asked questions

What is the regex for US phone number?
/^(?:\+1[-. ]?)?\(?([2-9]\d{2})\)?[-. ]?(\d{3})[-. ]?(\d{4})$/ — it matches the whole string. See the table above for what each part does.
Which examples match?
Of the examples tested, these match: (212) 555-0123, 212-555-0123, +1 415.555.0199, 4155550199. The others don’t.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.