-5

I'm new in php, I'm trying to validate a mobile number using Regular Expression. It's total length is 13 and must start with 88016 or 88017 or 88015 or 88018 or 88019 or 88011. So the number format is look like this:

88016XXXXXXXX OR 88015XXXXXXXX OR 88017XXXXXXXX OR 88019XXXXXXXX OR 88011XXXXXXXX

But I'm tired. Please see following code. I think there is a wrong in my expression..

if( !preg_match("/^([0-9]-)?[0-9]$/", $write_numer))            
     $err[] = "Please enter a valid phone number";

Thanks so much for your help.

Bora
  • 10,529
  • 5
  • 43
  • 73
Alex
  • 71
  • 6

3 Answers3

3

try this

if (preg_match("/^8801(6|5|7|9|1)\d{8}$/", $value)) {
        echo "yes";
}
elclanrs
  • 92,861
  • 21
  • 134
  • 171
rams0610
  • 1,041
  • 10
  • 8
  • 2
    `\d` matches any digit including foreign digits [Does ā€œ\dā€ in regex mean a digit?](http://stackoverflow.com/a/6479605/1700963) – Class Sep 16 '13 at 06:16
2

Try this:

$pattern = "/^(880)(16|15|17|19|11)(\d){8}$/";

if( !preg_match($patterm, $write_numer))            
     $err[] = "Please enter a valid phone number";
Jason OOO
  • 3,567
  • 2
  • 25
  • 31
1

This should do the trick:

preg_match("/^8801[5-7|1|9][0-9]{8}$/", $write_numer)
Class
  • 3,149
  • 3
  • 22
  • 31