How to validate phone number using PHP?

phone validation rules:-

1. phone numbers should be 10-12 digits in length
2. only numbers are accepted
3. "+" symbol in the beginning of the number is still acceptable

regx :/^[0-9]{10}+$/

code:


function validateMobile($mobile)
{
    $mobile=purify($mobile);
    if (preg_match('/^[0-9]{10}+$/', $mobile)) {
        $error="
Phone number is valid
"; $data = array("data" => $mobile,"msg"=>$error); return $data; } else { $error="
Invalid Phone number
"; $data = array("msg" => $error); return $data; } } validateMobile(7777777777);

output:

it returns array use

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post