##判斷字符串是否是漢字java
public boolean isChinese(String con) { for (int i = 0; i < con.length(); i = i + 1) { if (!Pattern.compile("[\u4e00-\u9fa5]").matcher( String.valueOf(con.charAt(i))).find()) { return false; } } return true; }
##判斷是否是中文或英文字母this
private boolean conValidate(String con) { if (null != con && !"".equals(con)) { if ((this.isChinese(con) || con.matches("^[A-Za-z]+$")) && con.length() <= 10) { return true; } } return false; }
##判斷字符串是否是數字code
public boolean isNumeric(String str) { Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); if( !isNum.matches() ) { return false; } return true; }