0

I'm trying to write a single regular expression to validate phone numbers. Below numbers should be

1111111111 or 111-111-1111 or 111.111.1111 - should fail and at the same time 767-789-9876 or 7677899876 should pass

I have come up with ^(?!([0-9])\1{2}[^d]\1{3}[^d]\1{4}$), but it only helps validate repetitive digits, alphanumeric characters and all succeed. Can anyone help me improve my regex?

1 Answers1

0

based on your examples, use this pattern

^(?!(\d)([.-]?\1)+$)(\d{3}[-.]?\d{3}[-.]?\d{4})

Demo

alpha bravo
  • 7,838
  • 1
  • 19
  • 23