天天看點

判斷字元串是否為數字&&判斷字元串是否為字母&&判斷子字元串是否為漢字

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;

}