//检测用户名合法性
public void checkUserName() {
String regex = "([a-z]|[A-Z]|[\u4e00-\u9fa5])+";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher("张三");
System.out.println("checkUserName : "+m.matches());
}
//检测15或18位身份证 15位是第一代身份证,18位是第二代身份证,末位可能是x
public void checkIdCard15Or18() {
String regex = "(^\d{18}$)|(^\d{15}$)|(^\d{17}(\d|X|x)$)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher("11222111222122122X");
System.out.println("checkIdCard : "+m.matches());
}
//检测是否是数字
public void checkIsNumber() {
String regex = "(^-?[1-9]\d*$)|(^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher("1234.21");
System.out.println("checkIsNumber : "+m.matches());
}