Reputation: 53
I have a RegularExpressionValidator that validates a password field. The password must contain letters and at least 1 number and must be between 8 and 20 characters. Here's my validator:
<asp:RegularExpressionValidator ID="regexPassword" runat="server" ControlToValidate="txtNewPassword"
ValidationExpression="^(?=.*[0-9])(?=.*[a-zA-Z])\w{8,20}$" ErrorMessage="Password must contain at least one digit and must be between 8 and 20 characters"
Text="*" ValidationGroup="Passwords"></asp:RegularExpressionValidator>
This works great in my development environment and when I works on my local machine but it doesn't work when I migrate it to the production environment. In the production environment, I must start off with a digit for it to pass. Our production environment is running a Win 2k8 R2 machine but I can't imaging that that would matter. I found another post in here saying that this expression would work so I tested it and indeed it did work...but only in my dev environment. Can anyone see why, in my production environment, I have have to start off with a number for this to work? The number should be anywhere in the password.
Thanks
Upvotes: 0
Views: 117
Reputation: 1827
Try this:
^(?=\w{8,20}$)(?=.*[0-9])(?=.*[a-zA-Z]).*
It relates to an IE6 bug, but it may still apply depending on the version of ASP.NET running on your production machine.
Upvotes: 1