We’re improving Formula Genius. We’re redesigning the app and fixing issues along the way. Sorry for any disruption, and thank you for your patience.
Regex intermediate

How to Match US Phone Numbers Using Regex?

Matching US phone numbers can be tricky due to various formats. This regex pattern simplifies the process by capturing multiple formats.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Match US phone numbers in formats like (555) 123-4567, 555-123-4567, and 5551234567"

Regex
^\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}$

This regex pattern matches US phone numbers in several common formats.

Step-by-step breakdown

  1. Starts with an optional '(' followed by 3 digits and an optional ')'.
  2. Allows for an optional space or hyphen after the area code.
  3. Follows with 3 digits, which may also be separated by an optional space or hyphen.
  4. Ends with 4 digits, ensuring the complete phone number is captured.

Edge cases & warnings

  • Input with letters or special characters will not match.
  • Phone numbers with incorrect digit counts will not match.
  • Formats with extra spaces or hyphens will not match.

Examples

Prompt

"(555) 123-4567"

Regex
Match
Prompt

"5551234567"

Regex
Match

Frequently asked questions

What formats does this regex support?

It supports formats like (555) 123-4567, 555-123-4567, and 5551234567.

Can this regex match international phone numbers?

No, this regex is specifically designed for US phone numbers.

What should I do if my phone number format is different?

You may need to modify the regex pattern to accommodate your specific format.

Can't find what you need?

Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.