PHP 匹配电话,手机,400号码 函数

来源:互联网 发布:学高中数学的软件 编辑:程序博客网 时间:2024/04/29 06:22
    function checkTel(){          var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;          var isMob=/^((\+?86)|(\+86))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;          var value=document.getElementById("ss").value.trim();          if(isMob.test(value)||isPhone.test(value){              return true;          }          else{              return false;          }          }  



    <?php            function isTel($tel,$type='')      {        $regxArr = array(        'sj'  =>  '/^(\+?86-?)?(18|15|13)[0-9]{9}$/',        'tel' =>  '/^(010|02\d{1}|0[3-9]\d{2})-\d{7,9}(-\d+)?$/',        '400' =>  '/^400(-\d{3,4}){2}$/',        );        if($type && isset($regxArr[$type]))        {          return preg_match($regxArr[$type], $tel) ? true:false;        }        foreach($regxArr as $regx)        {          if(preg_match($regx, $tel ))          {            return true;          }        }        return false;      }            $tm1 = microtime(true);      $arr = array(      '15910241024',      '+861591900 0000',      '86159 1930 9100',      '+86-15312001200',      '18655321002',            '02089571800',      '020-89571800',      '0755-102410240',      '0553-10241024',      '010-1204120140',      '010-120412014',      '110-89571800',      '022-102410240',      '0222-102410241',            '400-020-9800',      '400-0588-010',      '400-0211-0112',      );      foreach ($arr as $tel)      {          echo "\n{$tel}:\t".(isTel($tel) ? "是":"错误");      }      echo sprintf("\n\ntaken %.6f s",microtime(true)-$tm1);  


原创粉丝点击