public static boolean isAlpha(String s){
return s != null && s.matches("^[a-zA-Z]*$");
}
或者StringUtils
作为:
public static boolean isAlpha(String str){
return StringUtils.isAlpha(str);
}
或使用 Java:
public static boolean isAlpha(String s){
if (s == null) {return false;}
for (int i = 0; i < s.length(); i++){
char c = s.charAt(i);
if (!(c >= 'A' && c <= 'Z') && !(c >= 'a' && c <= 'z')) {
return false;
}
}
return true;
}
输出是:true
我打印了字符串,发现上述方法正在将波斯字符串转换为 unicode:چطوری
反正有没有得到只有字母和空格的字符串?