如何编写RegularExpressionValidator [英] how to write RegularExpressionValidator

查看:60
本文介绍了如何编写RegularExpressionValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写RegularExpressionValidator ValidationExpression,检查文本框中的第一个字符是否必须为大写?

how do i write RegularExpressionValidator ValidationExpression that checks that the first character must be Uppercase in a textbox ?

推荐答案

实际上,只要它转换第一个字符即可使用正则表达式匹配并替换的小写字母。



我没有理由要求用户将第一个字符大写,以便您可以验证它。



http://stackoverflow.com/questions/1668117/regex-how-to-uppercase-the-first-character-of-each-word [ ^ ]



正则表达式也应该用于验证,如果没有看到下面



http://stackoverflow.com/questions/8274562/regex-to-check-if-the-first-character-is-uppercase [ ^ ]
Actually, you just convert the first char if it''s lower case using regex match and replace.

I don''t see a reason to beg the user to capitalize the first char so you can validate it.

http://stackoverflow.com/questions/1668117/regex-how-to-uppercase-the-first-character-of-each-word[^]

The regex should work for validation as well, if not see below

http://stackoverflow.com/questions/8274562/regex-to-check-if-the-first-character-is-uppercase[^]


您可能对 C#Regex:支持的Unicode常规类别 [ ^ ]。

那里是大写的字符类: \p {Lu] 匹配任何Unicode大写(不仅是ASCII)。与 \p {Lu} 相反的是 \P {Lu} (参见大写P),其中在正则表达式中意味着:除了给定的类之外的所有类,即除了大写之外的所有类别

例如如果第一个字符不是大写,则会出错:
You might be interested in C# Regex: Supported Unicode General Categories[^].
There is a character class for upper case: \p{Lu] that matches any Unicode upper case (not only ASCII). The opposite of \p{Lu} is \P{Lu} (see upper case P), which means in the regex: all but the given class, i.e. all but upper case
E.g. error if the first character is not upper case:
if (Regex.Match(input, @"^\P{Lu]").Success) { /*error...*/ }



干杯

Andi


Cheers
Andi


这篇关于如何编写RegularExpressionValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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