Click here to Skip to main content
14,937,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need regular expression to check the password policy

and the password policy should :

length of password :minimum 6 letters
2 digits
1 Special sign

What I have tried:

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

is it write or not?? if not how to write it??
Posted
Updated 21-Nov-17 6:24am
Comments
Richard MacCutchan 21-Nov-17 9:11am
   
"is it write or not?"
Well what happens when you try it?

Quote:
Need regular expression to check the password policy

No, you 'want', but it is the wrong tool for the problem.
If password was "ABCDEF12$", RegEx would be Ok, but anything can be mixed, this is what makes the RegEx not appropriate.

You need to build a little piece of code like
set Counters
scan each char in password
  categorize the current char
  update marching Counter
check if Counters match the policy.
   
You're close, but you need two digits, whereas your pattern only checks for one. Try:
RegEx
^(?=.*\d.*\d)(?=.*[@$!%*?&#'()+,-./:;<=>[\]^_`{|}~"])[A-Za-z\d@$!%*?&#'()+,-./:;<=>[\]^_`{|}~"]{6,}

Regexper[^]

You should probably also allow for "special" characters other than the ones listed:
RegEx
^(?=.*\d.*\d)(?=.*[^A-Za-z\d]).{6,}
   
Comments
vinu paul 22-Nov-17 1:37am
   
thank you sir.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900