开发者

Can't get asp.net regular expression validator to work for blank passwords?

I do not want to allow blank passwords, but if I leave the textbox blank, the text property 开发者_开发百科from the regular expression does not show up until I enter at least 1 character. How do I allow it not to have a blank password? I tried using the + sign instead of the * sign, but it still did not work.

<asp:RegularExpressionValidator 
                                ControlToValidate="txtPassword" 
                                Display="Dynamic"
                                runat="server" 
                                Text="Invalid" 
                                ValidationExpression="^(?=.*\d{1})(?=.*[a-zA-Z]{2}).{7,}$"
                                ValidationGroup="UserRegistrationValidation">
</asp:RegularExpressionValidator>


A RegularExpressionValidator doesnt validate empty text by design. You need also a RequiredFieldValidator or have a look at the following link: RegularExpressionValidator not firing on white-space entry


That regex does not match an empty string, so i can only assume that asp.net isn't invoke the validator, try adding a required validator as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜