✏️ Explanatory Question
<!DOCTYPE html>
<html>
<body>
<input type="text" id="passwordField">
<p id ="demo"> </p>
<button onclick="validatePassword()"> submit </button>
<script>
function validatePassword() {
var txt = document.getElementById("passwordField").value;
// Check for password length 8
if(txt.length >= 8){
var patt1 = /[1-9]/g;
// Check for Atleast One Digit
if(txt.match(patt1))
{
document.getElementById("demo").innerHTML = "";
// Check for special symbol
var patt8 = /[!@#$%^&*(),.?":{}|<>_]/g;
if(txt.match(patt8))
{
document.getElementById("demo").innerHTML = "";
var patt2 = /[A-Za-z]/g;
// Check for Atleast One Character
if(txt.match(patt2))
{
document.getElementById("demo").innerHTML = "";
// Check for Atleast One Uppercase digit
var patt3 = /[A-Z]/g;
if(txt.match(patt3)){
document.getElementById("demo").innerHTML = "";
// Check for Atleast One Lower digit
var patt5 = /[a-z]/g;
if(txt.match(patt5)){
document.getElementById("demo").innerHTML = "Password Policy Matches";
}else{
document.getElementById("demo").innerHTML = "Atleast One Lower";
}
}else{
document.getElementById("demo").innerHTML = "Atleast One Upper";
}
// Check for Atleast One Lower digit
var patt4 = /[a-z]/g;
if(txt.match(patt4)){
document.getElementById("demo").innerHTML = "";
// check for atleast upper digit
var patt6 = /[A-Z]/g;
if(txt.match(patt6)){
document.getElementById("demo").innerHTML = "Password Policy Matches";
}else{
document.getElementById("demo").innerHTML = "Atleast One Upper";
}
}else{
document.getElementById("demo").innerHTML = "Atleast One Lower";
}
}
else{
document.getElementById("demo").innerHTML = "Atleast One lower and one Upper Character";
}
}
else{
document.getElementById("demo").innerHTML = "Atleast One Symbol";
}
}
else{
document.getElementById("demo").innerHTML = "Atleast One Digit";
}
}else
{
document.getElementById("demo").innerHTML = "Password not less than 8";
}
}
</script>
</body>
</html>