您的当前位置:首页正文

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

来源:图艺博知识网

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

public boolean isMobileNO(String mobiles) {

Pattern p = Pattern

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})(\\]?)$";

Matcher m = p.matcher(email);

return m.matches();

}

3、判断是否全是数字

public boolean isNumeric(String str) {

Matcher isNum = pattern.matcher(str);

if (!isNum.matches()) {

return false;

}

return true;

}

4、判断是否是身份证号

public static boolean isIdCard(String idcard){

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

}

Top