Link to home
Start Free TrialLog in
Avatar of jayme9
jayme9

asked on

Password Complexity with validation expressions

This regular expression requires you to enter at least one letter, followed by any number of word characters, followed by at least one number, followed by any number of word characters.

[a-zA-Z]+\w*\d+\w*

Unfortunately, I cannot dictate to the user which placeholder is to be a number or a letter or a special character.  What I really need is the following:

If I have an 8 digit password field, it must meet the following validation:
Minimum of 1 Cap Letter, 1 Special Char, and 1 Numeric

This way I can put this password complexity on the Registration Page where the user creates their own password.

Any ideas?

THank you,
Jayme
SOLUTION
Avatar of leechoonhwee
leechoonhwee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jayme9
jayme9

ASKER

I'll make it even simplier...

Here is the solution that allows the applicant to create their own password that meets the following complexity requirements: at least 8 characters long, with one lower case letter, one upper case letter, one digit, and one special character.

Password field ... On Validate --> Regular Expression Validation -->

^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+,?./;:"'<=>]).*$

Error msg states "Please enter a valid password."

That's all there is to it.  It works fine.

Jayme
What if I needed 2 Upper Case 2 Special Charectes 2 Numerals?
Avatar of jayme9

ASKER

I haven't tried this, but it would be along the lines of this:


^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[1-9]{2,})(?=.*[A-Z]{2,})(?=.*[!@#$%^&*()+,?./;:"'<=>]{2}).*$

It basically says validate a string that is at least 8 characters with:
at least 1 lower case letter (a-z)
at least 2 numbers (1-9)
at least 2 upper case letters (A-Z)
at least 2 special characters within the set (!@#$%^&*()+,?./;:"'<=>)

All that code would go behind your control's OnValidate event that is executed when a user clicks the submit button.  Again, I have not tried it, but it would probably be close to what I have above.

Jayme