Phone Number (US) regex
Matches US phone numbers in various formats.
/(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/gWhat it matches
Ten digits in the North American layout, with an optional +1 or 1 prefix, optional parentheses around the area code, and hyphens, dots or spaces as separators. It accepts the written forms people use: (555) 123-4567, 555.123.4567, +1 555 123 4567 and the unpunctuated 5551234567.
Railroad diagram
Read left to right. Every path through the diagram is a string the pattern accepts.
Drag to pan. Ctrl+scroll to zoom.
Breakdown
gFind all matches instead of stopping after the first\+?Literal "+", optional1Literal "1"[-.\s]?Match one of: Literal "-", Literal ".", Whitespace, optional\(?Literal "(", optional\d{3}Digit (0-9), exactly 3 times\)?Literal ")", optional[-.\s]?Match one of: Literal "-", Literal ".", Whitespace, optional\d{3}Digit (0-9), exactly 3 times[-.\s]?Match one of: Literal "-", Literal ".", Whitespace, optional\d{4}Digit (0-9), exactly 4 timesTest cases
Matches
(555) 123-4567+1-555-987-65435551234567
Does not match
555-1234not a phone number
Caveats
Format only. It cannot tell a real number from 000-000-0000, does not reject reserved area codes, and will find ten digits inside a longer run, so an account number can look like a phone number to it. US and Canada only; for anything international, normalise to E.164 and validate with a library.
More common patterns
Test this against your own input in the regex tester, browse the full pattern library, or check the syntax cheat sheet.