手机号正则表达式精简

Python018

手机号正则表达式精简,第1张

精简后:1/^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/

正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。

java手机号正则表达式:    /**    * 验证手机号码    *     * 移动号码段:139、138、137、136、135、134、150、151、152、157、158、159、182、183、187、188、147    * 联通号码段:130、131、132、136、185、186、145    * 电信号码段:133、153、180、189    *     * @param cellphone    * @return    */   public static boolean checkCellphone(String cellphone) {   String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$"   return check(cellphone, regex)  }     /**    * 验证固话号码    *     * @param telephone    * @return    */   public static boolean checkTelephone(String telephone) {   String regex = "^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$"  return check(telephone, regex)  }      

php手机号码正则表达式:<?php   //正则表达式   $tel = "15558530459"//手机号码  if(strlen($tel) == "11")   {   //上面部分判断长度是不是11位   $n = preg_match_all("/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/",$tel,$array)  /*接下来的正则表达式("/131,132,133,135,136,139开头随后跟着任意的8为数字 '|'(或者的意思)   * 151,152,153,156,158.159开头的跟着任意的8为数字   * 或者是188开头的再跟着任意的8为数字,匹配其中的任意一组就通过了   * /")*/     var_dump($array)//看看是不是找到了,如果找到了,就会输出电话号码的   }else   {   echo "长度必须是11位"  }   /*   * 虽然看起来复杂点,清楚理解!   * 如果有更好的,可以贴出来,分享快乐!   * */   ?>     

js手机号码正则表达式: function checkMobile(){    var sMobile = document.mobileform.mobile.value    if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){     alert("不是完整的11位手机号或者正确的手机号前七位")    document.mobileform.mobile.focus()    return false   }   }    

if(s1.matches(regex)){

System.out.println(s1)

}

if(s2.matches(regex)){

System.out.println(s2)

}

if(s3.matches(regex)){

System.out.println(s3)

}

if(s4.matches(regex)){

System.out.println(s4)

}

if(s5.matches(regex)){

System.out.println(s5)

}

//你能把完整的程序贴出来么

//你限定一下位数

public class RegexDemo {

public static void main(String[] args) {

String regex = "1(3|5|7|8)[0-9]{9}"

String num = "17623629758"

System.out.println(num.matches(regex))

}

}