简体   繁体   English

如何使用php验证手机号码?

[英]how to validate a mobile number using php?

i have created a contatct form.but i am struggling with the validating mobile number.to validat ethis mobile number i have few conditions.我创建了一个联系表格。但我正在努力验证手机号码。要验证这个手机号码,我几乎没有条件。

  1. it should contain 11 digits.它应该包含 11 位数字。
  2. should start with the number 947.应该以数字 947 开头。
  3. no spaces allowed不允许有空格

Here is my code这是我的代码

$Mnumber = "94775896789";
if(!empty($Mnumber)) // phone number is not empty
{
    if(preg_match('/^?947\d{8}$/',$Mnumber)) // phone number is valid
    {
        echo 'success';
    }
    else // phone number is not valid
    {
        echo 'Phone number invalid !';

    }
}
$Mnumber = Str_replace(" ", "", $Mnumber); //optional, if you want to help the user 
preg_match("/^(947\d{8})$/", $Mnumber, $reslut);

http://www.phpliveregex.com/p/fAa http://www.phpliveregex.com/p/fAa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM