my code is:
<?php
$phone = 18311111111;
if(ereg("^\d{11}$",$phone)){
echo "true";
} else {
echo "false";
}
?>
i get false? why?
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With