Validate Mobile number in php form

前端 未结 6 752
野趣味
野趣味 2021-01-18 17:47

I want to validate mobile number of 10 digits and also add a prefix of 0 when I enter into the database.



        
6条回答
  •  伪装坚强ぢ
    2021-01-18 18:19

    For Indian Mobile Numbers it will be easiest

    if(is_numeric($num)){
    if($num>=1000000000 && $num<=9999999999){
    $num="0".$num;
    }
    else{
    echo "Invalid Mobile Number";
    }
    }
    else{
    echo "Hey Buddy mobile numbers are always in digits";
    }
    

    This idea struck me because of the willingness of finding easy and some short of mind because the number(1000000000 ) is the lowest numerical value(10 digits) and the number (9999999999) is a highest numerical value that can be used as a mobile number in India. And one more thing code will run faster than other solutions.

提交回复
热议问题