Contact
US Phone Number Regex
US phone numbers follow the North American Numbering Plan: a three-digit area code, a three-digit exchange and a four-digit line number. Neither the area code nor the exchange may start with 0 or 1, and this pattern enforces that while allowing the formats people actually type, such as (415) 555-0100, 415.555.0100 or +1 415 555 0100. It is a good fit for US contact forms, appointment booking and lead capture. The limit is that parentheses are optional independently, so an unbalanced form like (415 555-0100 also matches.
Pattern (JavaScript)
/^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$/Starts at the start of the line/string, then (the text "+1", then one of the characters .-, optionally (zero or one time)), optionally (zero or one time), then a literal "(", optionally (zero or one time), then one of the characters 2-9, then a digit, exactly 2 times, then a literal ")", optionally (zero or one time), then one of the characters .-, optionally (zero or one time), then one of the characters 2-9, then a digit, exactly 2 times, then one of the characters .-, optionally (zero or one time), then a digit, exactly 4 times, then the end of the line/string.
Limit: Checks the format only; it cannot tell whether the number is in service.
Examples
Matches
- ✓ (415) 555-0100
- ✓ 415-555-0100
- ✓ +1 212.555.0199
Does not match
- ✗ 123-555-0100
- ✗ 415-155-0100
- ✗ 555-0100
Try it
0 matches (JavaScript engine)
(415) 555-0100
415-555-0100
+1 212.555.0199
123-555-0100
415-155-0100
555-0100Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$/g;
const text = "(415) 555-0100";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$')
text = '(415) 555-0100'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$/';
$text = '(415) 555-0100';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:\\+1[ .-]?)?\\(?[2-9][0-9]{2}\\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$");
String text = "(415) 555-0100";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$`)
text := "(415) 555-0100"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$");
var text = "(415) 555-0100";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$").unwrap();
let text = "(415) 555-0100";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:\+1[ .-]?)?\(?[2-9][0-9]{2}\)?[ .-]?[2-9][0-9]{2}[ .-]?[0-9]{4}$/
text = '(415) 555-0100'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why can the area code not start with 0 or 1?
- Under the North American Numbering Plan, area codes and exchange codes begin with digits 2 to 9. Rejecting 0 and 1 catches many typos and partial numbers.
- Does this pattern also accept Canadian numbers?
- Yes, Canada and several Caribbean countries share the same numbering plan and +1 country code. If you need US-only numbers, check the area code against a list in code.
- How do I store the number consistently?
- After a match, strip every non-digit, drop a leading 1 if present, and store the result as +1 followed by ten digits. That gives you a clean E.164 value.
Related patterns
- Australian Mobile Number^(?:\+61 ?|0)4[0-9]{2} ?[0-9]{3} ?[0-9]{3}$
- North American Toll-Free Number^(?:\+?1[ .-]?)?\(?8(?:00|33|44|55|66|77|88)\)?[ .-]?[0-9]{3}[ .-]?[0-9]{4}$
- Email Address^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$
- Fax Line with Label^(?:fax|f)\s*[:.]?\s*\+?[0-9(][0-9 ().-]{6,}[0-9]$