[英]Validation regular expression
Must be an integer between 10 to 100 inclusively.必须是介于 10 到 100(含)之间的 integer。
<asp:TextBox ID="Donation" Columns="20" MaxLength="3" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"ControlToValidate="Donation"
ErrorMessage="Please enter valid donation" ValidationExpression="*">
This is question1,i dont know how to write the validation expression.这是问题1,我不知道如何编写验证表达式。
Regular Expressions is a wonderful tool.正则表达式是一个很棒的工具。 You can use the following links to learn how it can provide your solution.
您可以使用以下链接了解它如何为您提供解决方案。 After making an attempt and posting it here, you'll likely find more assistance is forthcoming.
尝试并在此处发布后,您可能会发现即将获得更多帮助。
A regex is great at finding patterns in text, but not so good at numerical values and ranges.正则表达式擅长在文本中查找模式,但在数值和范围方面不太擅长。
However, there also exists a RangeValidator但是,也存在RangeValidator
<asp:RangeValidator id="Range1"
ControlToValidate="Donation"
MinimumValue="10"
MaximumValue="100"
Type="Integer"
EnableClientScript="false"
Text="The value must be from 10 to 100!"
runat="server"/>
Be sure to set the "Type" to "Integer" in your case.请务必根据您的情况将“类型”设置为“整数”。
If you really must use a regular expression, you can use "[1-9][0-9]|100"
:如果你真的必须使用正则表达式,你可以使用
"[1-9][0-9]|100"
:
fragment![]() |
explanation![]() |
---|---|
[1-9] ![]() |
a single digit from 1 to 9![]() |
[0-9] ![]() |
followed by another single digit from 0 to 9 (so together 10 - 99)![]() |
| ![]() |
OR![]() |
100 ![]() |
the exact text "100"![]() |
Note that a regex validator also checks that it matches the entire string (not just a substring, as would be the default).请注意,正则表达式验证器还会检查它是否匹配整个字符串(不仅仅是 substring,这是默认设置)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.