美文网首页
判断邮箱或者手机号码的格式是否正确

判断邮箱或者手机号码的格式是否正确

作者: 24K纯帅豆 | 来源:发表于2015-06-14 18:53 被阅读2462次

1、判断手机格式是否正确

public 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);

return m.matches();

}

2、判断邮箱格式是否正确

public 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();

}

3、判断是否全是数字

public boolean isNumeric(String str) {

Pattern pattern = Pattern.compile("[0-9]*");

Matcher isNum = pattern.matcher(str);

if (!isNum.matches()) {

return false;

}

return true;

}

4、判断是否是身份证号

public static boolean isIdCard(String idcard){

Pattern idNumPattern = Pattern.compile("^[1-9]

\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$");

//通过Pattern获得Matcher

Matcher idNumMatcher = idNumPattern.matcher(idcard);

//判断用户输入是否为身份证号

return idNumMatcher.matches();

}

相关文章

网友评论

      本文标题:判断邮箱或者手机号码的格式是否正确

      本文链接:https://www.haomeiwen.com/subject/kmzjqttx.html