1

I need to modify my regularexpressionvalidator code to require the user to meet the following password requirements:

a. Contains at least 2 uppercase characters: A, B, C etc.

b. Contains at least 2 lowercase characters: a, b, c, etc.

c. Contains at least 2 numbers: 1,2,3,4,5,6,7,8,9,0

d. Contains at least 2 special characters, i.e.

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

Current code only requires a 10 character password length:

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

1 Answer 1

0

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.. 
Sign up to request clarification or add additional context in comments.

3 Comments

@Gary.S i had used this form ^(.*?[a-z]){2,}.*?$
My mistake, it works however it has been answered in other questions on the site
This didn't work for me but put me on the right path. i ended up using: ^((?=(.*\d){2,})(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*[!@#$%&+~?]){2,})).{10,25}$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.