普通防爆pression只匹配字母 [英] Regular Expression to match only letters

查看:156
本文介绍了普通防爆pression只匹配字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写RegularEx pressionValidator ASP.NET Web控件一个普通的前pression。

常规前pression应该让所有字母而不是数字或特殊字符(例如:|£$%&安培; /()

任何想法,该怎么办呢?


解决方案

  ^ [A-ZA-Z] + $

验证长度大于或等于1的一个串,仅由ASCII字母

  ^ [^ \\ W \\ D _] + $

做同样的国际信件了。

说明:

  [^#匹配是不属于任何字符
\\ W#非字母数字字符(字母,数字,下划线)
\\ D#位数
_#或下划线
字符类]#结束

实际上,你得到 \\ W 负( \\ D _ )。

或者,您可以使用ASP.NET支持单向code性质的事实:

  ^ \\ p {L〕+ $

验证带统一的字符串长度为$ 1或更多的C $Ç字母。

I need write a regular expression for RegularExpressionValidator ASP.NET Web Controls.

The regular expression should ALLOW all alphabetic characters but not numbers or special characters (example: |!"£$%&/().

Any idea how to do it?

解决方案

^[A-Za-z]+$

validates a string of length 1 or greater, consisting only of ASCII letters.

^[^\W\d_]+$

does the same for international letters, too.

Explanation:

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

Effectively, you get \w minus (\d and _).

Or, you could use the fact that ASP.NET supports Unicode properties:

^\p{L}+$

validates a string of Unicode letters of length 1 or more.

这篇关于普通防爆pression只匹配字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆