How the pattern works
| Part | Meaning |
|---|---|
(?:\+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 falsePython
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.