Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why ereg("^\d{11}$",18311111111) is false?

Tags:

regex

php

ereg

my code is:

<?php
    $phone = 18311111111;
    if(ereg("^\d{11}$",$phone)){
        echo "true";
    } else {
        echo "false";
    }
?>

i get false? why?

like image 917
artwl Avatar asked Oct 07 '22 05:10

artwl


1 Answers

Because ereg does not support \d, you need use [0-9] instead.

And ereg is deprecated, use preg_match instead, then you could use \d.

if(preg_match("/^\d{11}$/",$phone)){
    echo "true";
} else {
    echo "false";
}
like image 77
xdazz Avatar answered Oct 10 '22 03:10

xdazz