Validate Mobile number in php form

前端 未结 6 758
野趣味
野趣味 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:07

    Improving pravin tripathi's answer:

    if(!ereg("^[7-9]{1}[0-9]{9}$", $mob)) { return false; }

    since ereg() is deprecated, you could use

    preg_match("/^[7-9]{1}[0-9]{9}$/i", $mobile_no)
    

    This will help you validate a mobile number from India, since they are 10 digits and start with 7, 8 or 9 as of today. You could always change the pattern if new digits get introduced.

提交回复
热议问题