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:
我有一个正则表达式验证器来验证密码字段。密码必须包含字母和至少一个数字,并且必须在8到20个字符之间。这是我的验证器:
<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.
这在我的开发环境和我在本地机器上工作时非常有效,但是当我将它迁移到生产环境时就不起作用了。在生产环境中,我必须从一个数字开始让它通过。我们的生产环境正在运行一台Win 2k8 R2机器,但我无法想象这有什么关系。我在这里找到了另一个帖子,说这个表达式可以用,所以我测试了它,它确实有用……但是只在我的开发环境中。谁知道为什么,在我的生产环境中,我必须从一个数字开始工作?密码应该在任何地方。
Thanks
谢谢
1 个解决方案
#1
1
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.
它与IE6的一个bug有关,但是它仍然可以根据ASP的版本来应用。在您的生产机器上运行。
#1
1
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.
它与IE6的一个bug有关,但是它仍然可以根据ASP的版本来应用。在您的生产机器上运行。