-2

I am a new Java developer, I want to know how to check if the string contains only English letters or not. I search the but I got answer in PHP. I have not tried anything because I don't know.

luk2302
  • 55,258
  • 23
  • 97
  • 137

2 Answers2

0

You can use Java regex for that:

if((!str.equals("")) 
            && (str != null) 
            && (str.matches("^[a-zA-Z]*$"))) {
// Do something
}
Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
0

you can try somthing like

char c = 'h';
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
 //english letter
}
Sideeg MoHammed
  • 375
  • 2
  • 10