Reputation: 47871
I have a regex that parses out the three parts of a phone number input - but it doesn't handle some cases like 5555555555 or 555-2342341
https://regex101.com/r/kO3bG1/4
^(?:\+?1?[-.\s]?)(\d{3})([-.\s])(\d{3})\2(\d{4})$
how can I modify it so it handles these cases as well?
Upvotes: 1
Views: 57
Reputation: 19194
Just added some more 0-1 quantifiers for the test cases you were missing:
^(?:\+?1?[-.\s]?)\(?(\d{3})\)?([-.\s])?(\d{3})([-.\s])?(\d{4})$
https://regex101.com/r/zJ3tF4/3
Upvotes: 2