Phone Number Formats
Phone numbers come in many formats. Let's build patterns that handle the variations.
Common US Formats
Phone numbers appear in many ways:
555-123-4567(555) 123-4567555.123.45675551234567+1 555-123-4567
Exercises
Flexible Separators
Country Code
Comprehensive Pattern
Extracting Parts
International Formats
Validation vs Extraction
For extraction (finding phones in text):
For validation (checking if input IS a phone):
Use ^ and $ for validation to ensure the entire input matches.
Practice Playground
Key Takeaways
- Phone formats vary widely by country
- Use character sets
[-. ]for flexible separators - Use
?to make separators optional - Group area codes:
(\d{3})or\(\d{3}\) - Add
^and$for validation (vs extraction) - Consider vanity numbers (letters) if needed

