Check password strength while typing using JavaScript

[code]var code = document.getElementById("mypassword");

var passwordstrength = document.getElementById("password-meter");
var display = document.getElementsByClassName("textbox")[0];

code.addEventListener("keyup", function() {
checkpassword(code.value);
});


function checkpassword(password) {
var strengthvalue = 0;
if (password.match(/[a-z]+/)) {
strengthvalue += 1;
}
if (password.match(/[A-Z]+/)) {
strengthvalue += 1;
}
if (password.match(/[0-9]+/)) {
strengthvalue += 1;
}
if (password.match(/[$@#&!]+/)) {
strengthvalue += 1;

}

switch (strengthvalue) {
case 0:
passwordstrength.value = 0;
break;

case 1:
passwordstrength.value = 25;
break;

case 2:
passwordstrength.value = 50;
break;

case 3:
passwordstrength.value = 75;
break;

case 4:
passwordstrength.value = 100;
break;
}
}[/code]


[code]<body>

<form>

<input type="password" id="mypassword" autocomplete="off">

<progress max="100" value="0" id="password-meter"></progress>

</form>
</body>
[/code]

Download

Leave a Reply

Your email address will not be published. Required fields are marked *