以下是手机号正确性判断过滤demo,欢迎吐槽! 首先我们要搞清楚现在已经开放了多少个号码段,国家号码段分配如下: 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 联通:130、131、132、152、155、156、185、186 电信:133、153、180、189、(1349卫通) 剩下的就是写正则表达式进行匹配了,如下:
1、最新版:
@Pattern(regexp = "1[3456789][0-9]\\d{8}")
2、旧版本:
"1[3456789][0-9]\\d{8}"
3、核心逻辑:
/**
* 通用判断
* @param telNum
* @return
*/
public static boolean isMobiPhoneNum(String telNum){
String regex = "^((13[0-9])|(15[0-9])|(18[0-9]))\\d{8}$";
Pattern p = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(telNum);
return m.matches();
}
/**
* 更严格的判断
* @param mobiles
* @return
*/
public static boolean isMobileNum(String telNum){
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(telNum);
return m.matches();
}