Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for 8 digit number beginning with two similar numbers?

I would like to validate 8 digit phone numbers that start with a double digit greater than 2.
eg: 33452334 would validate while 32222222 would not.
This is what I tried but it's not working since it doesn't make sure the two first digits are similar:

^[3-9]{2}\d{6}$
like image 663
Jiyda Moussa Avatar asked Dec 12 '22 03:12

Jiyda Moussa


1 Answers

Use this regex:

^([3-9])\1\d{6}$
  • ( ) to capture,
  • \1 to use a back reference.
like image 149
Unihedron Avatar answered Mar 24 '23 19:03

Unihedron