Regex to Validate a US Phone Number
Copy the pattern, paste your numbers below, and see which ones match. Below the tester: which formats it accepts and how to lock it to one.
Regex pattern
/(?:\+?1[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}/g
This matches a US phone number in common formats like (415) 555-2671, 415-555-2671 or +1 415.555.2671. It checks the shape only, not that the number is in service.
What this pattern matches
This matches US 10-digit phone numbers written the way people really write them: with or without parentheses, spaces, dots, or dashes, and with an optional +1 or 1 prefix.
How it works, part by part
(?:\+?1[\s.-]?)? — an optional country code, +1 or 1.
\(?\d{3}\)? — the three-digit area code, parentheses optional.
[\s.-]? — an optional space, dot, or dash separator.
\d{3}[\s.-]?\d{4} — the 3-digit prefix and 4-digit line number.
Accepting fewer formats
This is deliberately permissive so it finds numbers inside messy text. For a strict form field, anchor it with ^…$ and remove the separators you do not allow.
Use it in your code
import re
text = "Valid: (415) 555-2671, 415-555-2671, 4155552671, +1 415 555 2671. Too short: 555-2671."
pattern = r'''(?:\+?1[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}'''
for m in re.finditer(pattern, text):
print(m.group())
const text = "Valid: (415) 555-2671, 415-555-2671, 4155552671, +1 415 555 2671. Too short: 555-2671.";
const re = new RegExp(String.raw`(?:\+?1[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}`, "g");
console.log(text.match(re));
FAQ
Does it accept the +1 country code?
Yes, but it is optional. Both +1 415 555 2671 and 415-555-2671 match.
Will it reject a 7-digit number?
Yes. It requires a 3-digit area code plus 7 more digits, so 555-2671 alone will not match.
How do I validate a single field strictly?
Wrap it in ^ and $ so the whole input must be the number, not just contain one.