Reputation: 792
I have a requirement to validate the user names (contains only alphabet). But the user is entering in Spanish. I cannot use the common regx [A-Za-z]. Is it possible to validate this using java regular expressions?. Any suggestion on a different approach is also fine?
Upvotes: 3
Views: 743
Reputation: 17422
You could use \p{IsAlphabetic}
, or in the case of Spanish you could use [A-Za-zÁÉÍÓÚáéíóúÑñÜü]
Spanish is my first language :-)
Upvotes: 2
Reputation: 785196
Use unicode based letter symbol:
\\p{L}
Also you can create your pattern with Pattern.UNICODE_CASE
option to get unicode support:
Pattern p = Pattern.compile(regex, Pattern.UNICODE_CASE);
Upvotes: 2