Regex for US phone number
/(?:\+1[\s.-]?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\b/g
Matches
Examples
Note
Matches common North American formats. For anything international, store numbers in E.164 and validate with a phone library.
Matches in the example
"(555) 123-4567""555.123.4567""+1 555 123 4567"
Token by token
(?:a group, not capturing\+the character “+”1the character “1”[\s.-]?one of: a whitespace character, “.” or “-”, optionally)?end of group, whole group optionally\(?the character “(”, optionally\d{3}a digit (0–9), exactly 3 times\)?the character “)”, optionally[\s.-]?one of: a whitespace character, “.” or “-”, optionally\d{3}a digit (0–9), exactly 3 times[\s.-]?one of: a whitespace character, “.” or “-”, optionally\d{4}a digit (0–9), exactly 4 times\ba word boundary
Other patterns
- Email address
- URL
- IPv4 address
- UUID
- Hex color
- Date (YYYY-MM-DD)
- Time (24-hour)
- US phone number
- Phone number (E.164)
- US ZIP code
- Credit card number
- URL slug
- Username
- Strong password
- HTML tag
- Semantic version
- MAC address
- JSON Web Token
- Hashtag
- @mention
- Number
- Leading and trailing whitespace
- Repeated word
- Blank lines
- Markdown link
- Quoted string
- Domain name
- File extension
- Base64
- Trailing comma