duanhuayong6687 2017-04-09 07:43
浏览 16
已采纳

PHP手机验证

I have a problem with the registry, I want to do to verify 9 digits mobile.

Code:

$tel = $_POST['tel'];
$sdt_length = strlen($tel);
$sdt_check = substr($tel, 0, 2);
elseif (!preg_match("/^[0-9]*$/i", $tel))
elseif ( ($sdt_check == '09' && $sdt_length == 10) || ($sdt_check == '01' && $sdt_length == 11) ) {
  • 写回答

1条回答 默认 最新

  • dpcnm2132 2017-04-09 21:32
    关注

    Phone formats can differ greatly from region to region. I will assume that you are perfectly aware of the phone formats that you are dealing with and that they will not be POSTed with any kind of symbols.

    You need a 9 digit string or a 10 or 11 digit string depending on the first two digits: 09 or 01, use this:

    ^(?:09\d{8}|01\d{9}|\d{9})$
    

    See Demo

    The above pattern will check for digit-only strings and length based on the first two digits.

    PHP implementation:

    if(isset($_POST['tel']) && preg_match("/^(?:09\d{8}|01\d{9}|\d{9})$/",$_POST['tel'])){
        $tel=$_POST['tel'];
    }else{
        echo "Missing or Invalid Telephone Number";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。