1

我需要修改我的正则表达式验证器代码以要求用户满足以下密码要求:

一种。至少包含 2 个大写字符:A, B, C等。

湾。至少包含 2 个小写字符:a, b, c,等。

C。至少包含 2 个数字:1,2,3,4,5,6,7,8,9,0

d。至少包含2个特殊字符,即

! @ # $ % ^ & * ( ) _ + | ~ - = \ ` { } [ ] : " ; ' < > ? , . /

当前代码只需要 10 个字符的密码长度:

<asp:RegularExpressionValidator ID="valPassword" 
runat="server" ControlToValidate="txtPassword" 
ErrorMessage="Error: 10 character required password length"
ValidationExpression=".{10}.*" /> 
4

1 回答 1

0

你可以使用这个正则表达式

^(?=^.{10}$)(?=^(.*?[A-Z]){2,}.*?$)(?=^(.*?[a-z]){2,}.*?$)(?=^(.*?\d){2,}.*?$)(?=^(.*?[!@#$%^&]){2,}.*?$).*?$
   --------  ---------------------  --------------------- ------------------- --------------------------
      |               |                       |                    |                      |->checks for 2 or more special characters
      |               |                       |                    |->checks for 2 or more digits 
      |               |                       |->checks for 2 or more small letters
      |               |->checks for 2 or more capital words
      |
      |->checks for 10 words..
于 2012-11-26T10:37:47.930 回答