工作中使用频率比较高的常规验证器

  首先是一个邮箱的验证:

    

function is_email($email){
      return preg_match("/^[\w\-\.]+@[\w\-]+(\.\w+)+$/",$email)      
}

 

  其次是验证国内的电话号码:

 

  

function is_tel($tel){
      return preg_match("/^(\d{3,4}-)?(\d{7,8})(-(\d{3,}))?$/",$tel);
}

 

  验证手机号码:

 

  

function is_mobile($mobile){
      $mobile = ltrim($mobile,0);
      $pre3 = substr($mobile,0,3);
      if($pre3==852){
             return preg_match("/^852\d{8,9}$/",$mobile);
      }
      else{
             if (strlen($mobile) != 11){
                    retrun false;
             }
             else{
                    return preg_match("/^1[3458]\d{9}$/",$mobile);
             }
      }
}    

 

posted @ 2014-03-19 11:25  hl0128  阅读(167)  评论(0)    收藏  举报