最近又需要实现java手机号码正则表达式验证,我上次写的 Java手机号码正则表达式验证,手机号段根据2020年最新号段所做参考 已经不全了,我今天也查了一下最新的手机号段,重新写一遍(这次包括了虚拟运营商)。2024年最新的号段我参考自 :https://m.jihaoba.com/tools/haoduan/
目前的移动号段:139, 138, 137, 136, 134, 135, 147, 150, 151, 152, 157, 158, 159, 172, 178, 182, 183, 184, 187, 188, 195, 197, 198
联通号段:130, 131, 132, 140, 145, 146, 155, 156, 166, 185, 186, 175, 176, 196
电信号段:133, 149, 153, 177, 173, 180, 181, 189, 190, 191, 193, 199
广电号段:192
虚拟运营商号段:162, 165, 167, 170, 171
判断手机号的方法isMobile
public boolean isMobile(String mobiles) {
Pattern p = Pattern.compile("^((13[0-9])|(14[0|5|6|7|9])|(15[0|1|2|3|5|6|7|8|9])|(16[2|5|6|7])|(17[0|1|2|3|5|6|7|8])|(18[0-9])|(19[0|1|2|3|5|6|7|8|9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
以及main方法
public static void main(String[] args) {
boolean b = isMobile("13919190810");
if (b==true){
System.out.println("手机号符合规则。");
}else {
System.out.println("这个号码不符合规则");
}
}