Last updated on February 21st, 2022 at 07:29 am

Here is simple method to check the password strength using javascript, just copy and paste the script given below in your registration field and customize it accordingly.Add this code below inside the body tags of your page.

Some bugs have been fixed and the script is working fine now.

<h2>Type something on the input box</h2>
<script language="javascript">
function passwordCheck()
{var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z]) (?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
var pwd = document.getElementById("password");
if (pwd.value.length==0) {
document.getElementById('check').innerHTML = 'Type Password';
} else if (false == enoughRegex.test(pwd.value)) {
document.getElementById('check').innerHTML = 'More Characters';
} else if (strongRegex.test(pwd.value)) {
document.getElementById('check').innerHTML = '<b><span style="color:green">Strong!</span>';
} else if (mediumRegex.test(pwd.value)) {
document.getElementById('check').innerHTML = '</b><b><span style="color:orange">Medium!</span>';
} else {
document.getElementById('check').innerHTML = '</b><b><span style="color:red">Weak!</span>';
}}
</script>
<input name="password" id="password" type="text" size="15" maxlength="20" onkeyup="return passwordCheck();" />
<span id="check">Type Password</span>

Demo

Thank you very much.

Leave a Reply

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