/^ : Start
(?=.{8,}) : Length
(?=.*[a-zA-Z]) : Letters
(?=.*d) : Digits
/^(?=.*[!#$%&?*^()~` "])$/ : Special characters
$/ : End
(/^
(?=.*d) //should contain at least one digit
(?=.*[a-z]) //should contain at least one lower case
(?=.*[A-Z]) //should contain at least one upper case
[a-zA-Z0-9]{8,} //should contain at least 8 from the mentioned characters
$/)
Example:- /^(?=.*d)(?=.*[a-zA-Z])[a-zA-Z0-9]{7,}$/
function validate() {
var p = document.getElementById('pass').value
var errors = []
//if (p.length < 8) {
// errors.push("Your password must be at least 8 characters")
//}
if (p.search(/[a-z]/) < 0) {
errors.push("Your password must contain at least one lowercase letter.")
}
if (p.search(/[A-Z]/) < 0) {
errors.push("Your password must contain at least one uppercase letter.")
}
if (p.search(/[0-9]/) < 0) {
errors.push("Your password must contain at least one digit.")
}
if(p.search(/[!@#$\%^&*()\_+.,;:-]/) < 0) {
errors.push("Your password must contain at least one special character.")
}
if (errors.length > 0) {
document.getElementById("errors").innerHTML = errors.join("<br>")
return false;
}
return true;
}
const regexPass = /(?=.*[!#$%&?^*@~() "])(?=.{8,})/;
//eight char or longer and must have a special character
for REACT INPUT TAG
var errorMessage:
"Password should be 8-20 characters and include at least 1 letter, 1 number and 1 special character!",
<input name= "password",
type= "password",
placeholder= "Password",
pattern="^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,20}$",
required/>