Regex for Phone Number (US)
Validates US phone numbers in various formats: (555) 123-4567, 555-123-4567, 5551234567.
Pattern
/^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Live Tester
Enter a string to test
Examples
✓ (555) 123-4567
✓ 555-123-4567
✓ 5551234567
✗ (055) 123-4567
✗ 123-4567
✗ 555-1234-567
Pattern Breakdown
^\(?[2-9]\d{2}\)? — area code with optional parentheses
[-.\s]? — optional separator
\d{3} — exchange code (3 digits)
[-.\s]?\d{4}$ — separator + subscriber number (4 digits)
Code Snippets
Javascript
const regex = /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/;
regex.test("(555) 123-4567"); // true Python
import re
pattern = r"^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$"
bool(re.match(pattern, "(555) 123-4567")) # True Php
$pattern = '/^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/';
preg_match($pattern, "(555) 123-4567"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/ IPv6 Address /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/