I am trying to get data only in English language.
I tried different methods like:
public static boolean isAlpha(String s){
return s != null && s.matches("^[a-zA-Z]*$");
}
Or StringUtils
as:
public static boolean isAlpha(String str){
return StringUtils.isAlpha(str);
}
OR using 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;
}
Output is: true
I printed the string and found that aforementioned methods are converting Persian String into unicode as: چطوری
Is there anyway to get String of only alphabet letters and spaces?