Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I validate 13 digit phone number with hyphen?

I have a phone number formatted like this.+251-911-123456.

How could I create a regex that matches the given format.

I was trying to do it with the bellow given expression but it is not a success.

^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
like image 423
Melaku Minas Kasaye Avatar asked Dec 10 '25 21:12

Melaku Minas Kasaye


1 Answers

You may use

/^\+\d{3}-\d{3}-\d{6}$/

Details

  • ^ - start of string
  • \+ - a + symbol
  • \d{3} - three digits
  • - - a hyphen
  • \d{3} - three digits
  • - - a hyphen
  • \d{6} - six digits
  • $ - end of string.

See the regex demo and the Regulex graph:

enter image description here

like image 156
Wiktor Stribiżew Avatar answered Dec 12 '25 09:12

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!