document.getElementById('password').oninput = function () { var password = this.value; var strengthText = document.getElementById('password-strength'); var strength = getPasswordStrength(password); strengthText.innerHTML = strength.text.replace(/&/g, "&").replace(//g, ">"); strengthText.className = strength.class; }; function getPasswordStrength(password) { var strength = { text: '', class: '' }; if (password.length < 6) { strength.text = 'Weak'; strength.class = 'password-weak'; } else if (password.length < 10) { strength.text = 'Medium'; strength.class = 'password-medium'; } else { var hasUpperCase = /[A-Z]/.test(password); var hasLowerCase = /[a-z]/.test(password); var hasNumbers = /\d/.test(password); var hasSpecialChars = /[!@#$%^&*(),.?":{}|<>]/.test(password); if (hasUpperCase && hasLowerCase && hasNumbers && hasSpecialChars) { strength.text = 'Strong'; strength.class = 'password-strong'; } else { strength.text = 'Medium'; strength.class = 'password-medium'; } } return strength; }