java 判断手机号的正则

 
  1. 中国电信号段 133、149、153、173、177、180、181、189、199

  2. 中国联通号段 130、131、132、145、155、156、166、175、176、185、186

  3. 中国移动号段 134、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198

  4. 14号段以前为上网卡专属号段,如中国联通的是145,中国移动的是147等等。

  5. 虚拟运营商

  6. 电信:1700、1701、1702

  7. 移动:1703、1705、1706

  8. 联通:1704、1707、1708、1709、171

卫星通信:1349

 public class PhoneFormatCheckUtils {  
  
    /** 
     * 大陆号码或香港号码均可 
     */  
    public static boolean isPhoneLegal(String str)throws PatternSyntaxException {  
        return isChinaPhoneLegal(str) || isHKPhoneLegal(str);  
    }  
  
    /** 
     * 大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数 
     * 此方法中前三位格式有: 
     * 13+任意数 
     * 15+除4的任意数 
     * 18+除1和4的任意数 
     * 17+除9的任意数 
     * 147 
     */  
    public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {  
        String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";  
        Pattern p = Pattern.compile(regExp);  
        Matcher m = p.matcher(str);  
        return m.matches();  
    }  
  
    /** 
     * 香港手机号码8位数,5|6|8|9开头+7位任意数 
     */  
    public static boolean isHKPhoneLegal(String str)throws PatternSyntaxException {  
        String regExp = "^(5|6|8|9)\\d{7}$";  
        Pattern p = Pattern.compile(regExp);  
        Matcher m = p.matcher(str);  
        return m.matches();  
    }  
      
}  

 

你可能感兴趣的:(JAVA)