asp.net - 正则表达式只匹配字母

标签 asp.net regex

我需要为 RegularExpressionValidator ASP.NET Web 控件编写一个正则表达式。

正则表达式应允许所有字母字符,但不允许数字或特殊字符(例如:|!"£$%&/())。

知道怎么做吗?

最佳答案

^[A-Za-z]+$

验证长度为 1 或更大的字符串,仅由 ASCII 字母组成。
^[^\W\d_]+$

对国际信件也是如此。

解释:
[^   # match any character that is NOT a
\W   # non-alphanumeric character (letters, digits, underscore)
\d   # digit
_    # or underscore
]    # end of character class

有效地,您将获得 \w减去( \d_ )。

或者,您可以使用 ASP.NET 支持 Unicode 属性的事实:
^\p{L}+$

验证长度为 1 或更多的 Unicode 字母字符串。

关于asp.net - 正则表达式只匹配字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3707591/

相关文章:

regex - 使用正则表达式查找名称

python - 删除行的正则表达式

c++ - 如何将 pcre_study 与 pcrecpp 一起使用?

asp.net - 如何在开发机器上测试子域? abc.localhost

javascript - Chrome 刷新 "resubmit form data"提交 Null

asp.net - 在运行时更改 SqlDataSource.SelectCommand 会中断分页

regex - 是否有提供正则表达式静态分析的库?

mysql - ASPNET5 .Net Core 支持 MySql EntityFramework

c# - PDFsharp - 使用私有(private)字体

.net - 正则表达式 - 重复组