Need assistance with a Regular Expression

chapmanjw
chapmanjw used Ask the Experts™
on
Hello, just need assistance writing a regular expression for the ASP.NET RegularExpressionValidator control to validate the following requirements on a password field:

Between 8 & 16 characters, at least 1 uppercase letter, at least 1 lowercase letter, at least 1 number, and at least 1 symbol.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Try this. Add or remove any special symbols from the last group--just be sure to leave the outer square brackets. Also, if you plan to allow hyphens, the include hyphen as either the first or last character inside the square brackets of the last group.
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,16}$

Open in new window

kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
If you need help understanding the pattern, have a look at my article. I discuss this exact scenario in the section "Real World Examples" near the end of the article. The first example, "Passwords Containing Special Characters and of a Specific Length," explains why this works.

Author

Commented:
It works perfectly, thanks so much.  I used RegEx so infrequently, glad to know someone knows what they are doing :)
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help  = )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial