public
class
ClassPathResource {
public
static
boolean
isMobileNO(String mobiles) {
Pattern p = Pattern
.compile(
"^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$"
);
Matcher m = p.matcher(mobiles);
System.out.println(m.matches() +
"---"
);
return
m.matches();
}
public
static
void
main(String[] args)
throws
IOException {
System.out.println(ClassPathResource.isMobileNO(
"18977778989"
));
}
}
|
要严格的验证手机号码,必须先要清楚现在已经开放了哪些数字开头的号码段,目前国内号码段分配如下:
移动: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卫通)
从网上看了许多的关于email 和手机号码的验证。还是被我找到了可以验证成功的。我已经做过测试了。分享一下
public static boolean isEmail(String strEmail) {
String strPattern = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(strEmail);
if (m.matches()) {
return true;
}else {
return false;
}
}
Pattern pattern = Pattern.compile("1[0-9]{10}");
Matcher matcher = pattern.matcher(str);
if (matcher.matches()) {
return true;
}else {
return false;
}