I want a regular expression to check that:
A password contains at least eight characters, including at least one number and includes both lower and uppercase letters and special characters, for example #
, ?
, !
.
It cannot be your old password or contain your username, "password"
, or "websitename"
And here is my validation expression which is for eight characters including one uppercase letter, one lowercase letter, and one number or special character.
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$"
How can I write it for a password must be eight characters including one uppercase letter, one special character and alphanumeric characters?
A more "generic" version(?), allowing none English letters as special characters.
You can use the below regular expression pattern to check the password whether it matches your expectations or not.
Pattern to match at least 1 upper case character, 1 digit and any special characters and the length between 8 to 63.
"^(?=.[a-z])(?=.[A-Z])(?=.*\d)[a-zA-Z\d\W]{8,63}$"
This pattern was used for JAVA programming.
According to your need this pattern should work just fine. Try this,
Just create a string variable, assign the pattern, and create a boolean method which returns true if the pattern is correct, else false.
Sample:
Hope the below works. I tried this in Azure custom policy.
^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[@#$%^&*-_+=[]{}|\:',?/
~"();!])([A-Za-z\d@#$%^&*\-_+=[\]{}|\\:',?/
~"();!]|.(?!@)){6,16}$A solution I found in one of the previous answer as:
Minimum 8 characters at least 1 Uppercase Alphabet, 1 Lowercase Alphabet, 1 Number and 1 Special Character: "^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[$@$!%?&])[A-Za-z\d$@$!%?&]{8,}"
...didn't work for me, but the following is a simplified version and works great (add any special character you like, I added # here), and add the number rule as you do with the letters as: