0

My requirement is a bit different from the normal international phone number validations.

I want a regex which:

  1. Need to limit the phone number to 10.
  2. If a "-" is entered, then a 4 max character limit should be set before the "-", and after that 10 character limit.

Example : 1234567890,123456789, 0000-1234567890, 000-123456789 (area code- phonennumber)

Can someone point me to a regex which validates this? I did look through a lot of links, links.

Thanks

Community
  • 1
  • 1
Nevin Madhukar K
  • 3,031
  • 2
  • 25
  • 52

1 Answers1

3
^(?:\d{1,4}-)?\d{1,10}$

You can use this.See demo.

https://regex101.com/r/hE4jH0/3

You have not defined a lower limit.So this will match 0-0 too.You can replace 1 with whatever lower limit you want.

vks
  • 67,027
  • 10
  • 91
  • 124