DD
DevDash

Regex for US Phone Number

Regex Pattern

^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$

US phone number in common formats

Quick Answer

The regex pattern for us phone number is `^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$`. US phone number in common formats. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
(555) 123-4567✓ Matches
555-123-4567✓ Matches
5551234567✓ Matches
555.123.4567✓ Matches
555-12-34567✗ No match
+1 555 123 4567✗ No match
123-456✗ No match

Code Examples

javascript

const regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
const isValid = regex.test(value);

python

import re
pattern = r'^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/', $value)) {
    echo "valid";
}

java

String pattern = "^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.