导航

最全的手机号、邮箱java正则表达式

Posted on 2017-07-13 11:54  猿起  阅读(199)  评论(0)    收藏  举报

//判断手机格式是否正确
public static boolean isMobileNO(String mobiles) {
Pattern p = Pattern.compile("^(13[0-9]|14[5|7|9]|15[0|1|2|3|5|6|7|8|9]|17[0|1|6|7|8]|18[0-9])\\d{8}$");

Matcher m = p.matcher(mobiles);

return m.matches();
}

//判断email格式是否正确
public static boolean isEmail(String email) {
String str = "^([a-zA-Z0-9_\\-.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
Pattern p = Pattern.compile(str);
Matcher m = p.matcher(email);

return m.matches();
}