1

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?

guido
  • 18,391
  • 4
  • 70
  • 92
MonkeyBonkey
  • 43,529
  • 77
  • 242
  • 443

1 Answers1

2

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

guido
  • 18,391
  • 4
  • 70
  • 92