你想
\ p {L}:任何類型的任何語言字母。
從regular-expressions.info
\p{L}
或\pL
是具有財產 「字母」 的Unicode編碼表的每一個字符。所以它會匹配unicode表中的每個字母。
您可以在字符類中使用這樣的
ValidationExpression="^[\p{L}''-'\s]{1,40}$"
工作C#測試:
String[] words = { "O'Conner", "Smith", "Müller", "fooñ", "Fooobar12" };
foreach (String s in words) {
Match word = Regex.Match(s, @"
^ # Match the start of the string
[\p{L}''-'\s]{1,40}
$ # Match the end of the string
", RegexOptions.IgnorePatternWhitespace);
if (word.Success) {
Console.WriteLine(s + ": valid");
}
else {
Console.WriteLine(s + ": invalid");
}
}
Console.ReadLine();
我還沒來得及尚未嘗試這一點,但我會給它一個去提供反饋信息。儘管如此,這對我很有意義,所以感謝您的幫助。 – bobbo 2012-02-27 16:31:04
我試過這個,但它似乎仍然失敗,例如,如果我鍵入包含 - 字符的名字不起作用。更糟糕的是,英文中的正常名稱是不允許的?我很困惑。 – bobbo 2012-02-28 10:22:36
我無法用asp.net測試它,但它在c#上工作,所以我會說正則表達式應該沒問題。 – stema 2012-02-28 10:41:02