14

I've this regex:

if (cadena.matches("^[a-zA-Z ]+$")) return true;

It's accepting from A to Z as lowercase and uppercase. Also accepting spaces.

But this is working just for english. For instance, in Catalan we've the 'ç' character. Also we've characters with 'á', or 'à', etc.

Did some google and I couldn't find any way to do this.

I found out that I can filter for UTF-8 but this would accept characters that are not really a letter.

How can I implement this?

4

2 回答 2

26

使用这个正则表达式:

[\p{L}\s]+

\p{L}表示任何 Unicode 字母。

fiddle.re 演示

于 2013-06-07T09:42:43.643 回答
-2

查看文档并使用一个类(例如\p{InLATIN_1_SUPPLEMENT})。

于 2013-06-07T09:42:22.960 回答