天天看点

判断字符串是否为数字&&判断字符串是否为字母&&判断子字符串是否为汉字

1.数字

public static boolean isNum(String str){

  return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");

}

2.字母

if(String.matches("^[a-z,A-Z].*$")) {

}

3.汉字

public static boolean isContainChinese(String str) {

Pattern p = Pattern.compile("[\u4e00-\u9fa5]");

Matcher m = p.matcher(str);

if (m.find()) {

return true;

}

return false;

}