Reputation: 7733
I want to be sure that a String contains only alpha characters (with special character like "é", "è", "ç", "Ç", "ï"
, etc etc.).
I did that, but with special characters returns false...
if (myString.matches("^[a-zA-Z]+$")) {
return true;
}
Thanks guys!
Upvotes: 7
Views: 1289
Reputation: 369054
You can use Unicode Category: \\p{L}
or \\P{Letter}
to match any kind of letter from any language.
if (myString.matches("\\p{L}+")) {
return true;
}
BTW, String.matches
try to match entire string, so ^
, $
anchors are not necessary.
Upvotes: 7