手机号码格式化

来源:互联网 发布:饺子皮 知乎 编辑:程序博客网 时间:2024/06/10 15:22
/**
* 手机号码格式化
* @param number
* @return
*/
public static boolean numCorrect(String number) {
if (number.contains(" ")) {
number = number.replaceAll(" ", "");
}
// 中国移动:134[0-8],135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,17**
// ^1(34[0-8]|(3[5-9]|5[0127-9]|8[23478]|7[0-9])\\d)\\d{7}$
boolean chinaMobile = number
.matches("^1(34[0-8]|(3[5-9]|5[0127-9]|8[23478]|7[0-9])\\d)\\d{7}$");
// 中国联通:China Unicom 130,131,132,155,156,185,186,17


boolean chinaUnicom = number.matches("^1(3[0-2]|5[56]|8[56]|7[6])\\d{8}$");
boolean chinaTelecom = number.matches("^1((33|53|8[09]|7[0-9])[0-9]|349)\\d{7}$");
if (chinaMobile || chinaUnicom || chinaTelecom) {
return true;
} else {
return false;
}
}
0 0