US Phone Number
Match US phone numbers in common formats: (555) 867-5309, 555-867-5309, 5558675309.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("\\(?\\d{3}\\)?[\\s.\\-]?\\d{3}[\\s.\\-]?\\d{4}", "g");
const input = "(555) 867-5309";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}")
input_text = "(555) 867-5309"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}`)
input := `(555) 867-5309`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
\(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4} (flags: g)Raw source: \(?\d{3}\)?[\s.\-]?\d{3}[\s.\-]?\d{4}
How it works
Examples
Input
(555) 867-5309Matches
(555) 867-5309
Input
555.867.5309Matches
555.867.5309
Input
5558675309Matches
5558675309
Common use cases
- •Contact form validation
- •Extracting phone numbers from documents
- •CRM data normalisation
- •Marketing list cleaning
Related patterns
International Phone Number (Loose)
ValidationMatch international phone numbers in a variety of loose formats including country codes, area codes, and separators.
International Phone (E.164)
ValidationValidate phone numbers in ITU-T E.164 international format: a + sign followed by 2–15 digits, first digit non-zero.
Credit Card Number
ValidationMatch 16-digit credit card numbers with optional spaces or hyphens between groups of 4.
US Social Security Number
ValidationMatch US Social Security Numbers in the canonical XXX-XX-XXXX format.
Related concepts
Character Classes: \d, \w, \s and Their Negations
ConceptShorthand character classes match broad categories of characters. \d is a digit, \w is a word character, \s is whitespace. Uppercase negates.
Quantifiers: *, +, ?, and {n,m}
ConceptQuantifiers repeat the preceding element. * is 0 or more, + is 1 or more, ? is 0 or 1. {n}, {n,}, and {n,m} give exact counts and ranges.
How to Match Digits in Regex
How-toUse \d for any digit, [0-9] for ASCII digits only, or {n} to match a specific count of digits. Combine with anchors for whole-string validation.
How to Match an Optional Group
How-toPut a ? after a character, group, or character class to make it optional. Groups with ? match zero or one occurrence of the whole group.