InRegex Logo
InRegex
Neu

Comprehensive US Phone Number Validator

Erklärung

This regex pattern validates US phone numbers with the following format: (optional area code in parentheses or without, optional space), 3 digits, hyphen, 3 digits, hyphen, 4 digits, and an optional extension starting with 'x' followed by 1 to 5 digits.

python

Regulärer Ausdruck

^(\(\d{3}\) ?|\d{3}-)?\d{3}-\d{4}( x\d{1,5})?$
Kopieren
Haben Sie Feedback?
python

Beispielverwendung

import re

phone_number = '555-123-4567'
if re.match(r'^(\(\d{3}\) ?|\d{3}-)?\d{3}-\d{4}( x\d{1,5})?$', phone_number):
    print('Valid US phone number')
else:
    print('Invalid US phone number')
Kopieren

Ähnliche Reguläre Ausdrücke