简体   繁体   English

ASP.NET 4.0 RegularExpressionValidator

[英]asp.net 4.0 regularExpressionValidator

I need to modify my regularexpressionvalidator code to require the user to meet the following password requirements: 我需要修改我的regularexpressionvalidator代码,以要求用户满足以下密码要求:

a. 一种。 Contains at least 2 uppercase characters: A, B, C etc. 包含至少2个大写字符: A, B, C等。

b. b。 Contains at least 2 lowercase characters: a, b, c, etc. 包含至少2个小写字符: a, b, c,等。

c. C。 Contains at least 2 numbers: 1,2,3,4,5,6,7,8,9,0 包含至少2个数字: 1,2,3,4,5,6,7,8,9,0

d. d。 Contains at least 2 special characters, ie 至少包含2个特殊字符,即

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

Current code only requires a 10 character password length: 当前代码仅需要10个字符的密码长度:

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

You can use this regex 您可以使用此正则表达式

^(?=^.{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..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM