I want such a validation that My String must be contains at least one alphabet.
I am using the following:
String s = "111a11";
boolean flag = s.matches("%[a-zA-Z]%");
flag gives me false even though a is in my string s
I want such a validation that My String must be contains at least one alphabet.
I am using the following:
String s = "111a11";
boolean flag = s.matches("%[a-zA-Z]%");
flag gives me false even though a is in my string s
You can use .*[a-zA-Z]+.* with String.matches() method.
boolean atleastOneAlpha = s.matches(".*[a-zA-Z]+.*");
The regular expression you want is [a-zA-Z], but you need to use the find() method.
This page will let you test regular expressions against input.
and here you have a Java Regular Expressions tutorial.