I use RegularExpressionValidator control to verify TextBox control named TextBox1, the web form in VS2003 Web application, like below:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server" ErrorMessage="Fromat error."
ValidationExpression="^(?=.*[0-9])(?=.*[a-zA-Z]).{8,10}$" ControlToValidate="TextBox1"></asp:RegularExpressionValidator>
When I input string “qwer1asd”, it does not match. But the same regular expression:
^(?=.*[0-9])(?=.*[a-zA-Z]).{8,10}$
…matches in JavaScript. How do I fix it?
Try this regex:
There’s a bug in older versions of Internet Explorer (described here) that caused a regex like this to fail in the client even though it worked on the server. (That sounds like the opposite of what you’re describing, but I don’t see any other reason why your regex would fail.) Moving the length check to the first lookahead is the proven workaround for the bug.