这个正则表达式验证器不应该确保用户在文本框中输入内容吗?出于某种原因,一个空的文本框会通过。
<asp:RegularExpressionValidator ID="revNumericValidator" runat="server" ValidationExpression="^\d+$"
ControlToValidate="tb1" ErrorMessage="Please enter blah (must be a number)." />
最佳答案
按照惯例验证器不验证空文本。如果你想要一个值,你还必须添加一个 RequiredFieldValidator .
MSDN说
Validation succeeds if the input control is empty. If a value is required for the associated input control, use a RequiredFieldValidator control in addition to the RegularExpressionValidator control.
关于asp.net - 正则表达式验证器允许空作为输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/777993/