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?
Just we can do this by using HTML5.
Use below code in pattern attribute,
It will work perfectly.
Minimum eight characters, at least one letter and one number:
Minimum eight characters, at least one letter, one number and one special character:
Minimum eight characters, at least one uppercase letter, one lowercase letter and one number:
Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:
Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character:
You can use this regex:
This regex will enforce these rules:
(?=.*?[A-Z])
(?=.*?[a-z])
(?=.*?[0-9])
(?=.*?[#?!@$%^&*-])
.{8,}
(with the anchors)Just a small improvement for @anubhava's answer: Since special character are limited to the ones in the keyboard, use this for any special character:
^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$
This regex will enforce these rules:
Link check online https://regex101.com/r/mqGurh/1
Import the JavaScript file
jquery.validate.min.js
.You can use this method: