Abhilash
Abhilash

Reputation: 792

Java support for non english regular expressions

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

Answers (2)

morgano
morgano

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

anubhava
anubhava

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

Related Questions