Reputation: 175
I have a regex that trying to match these phone number format. I'm super close except 1 scenario:
Regex: ^\(?(\d{3})\)?[-\. ]?(\d{3})[-\. ]?(\d{4})$
Phone number format are trying to match:
I also want to match this.... there is leading spaces before and after the area code:
[empty spaces] (123) [emtpy spaces] 456-7890
Upvotes: 0
Views: 117
Reputation: 4489
^\s*\(?(\d{3})\)?[-\. ]*(\d{3})[-. ]?(\d{4})$
This should do it.
The *
character means 0 or more of preceding.
Regexr is probably the best tool I know to figure out how to change regex patterns.
Upvotes: 3