function validate_form(minlength) { var pass = validate_password(minlength); return validate_confirm() && pass; } function validate_confirm() { var password = document.getElementById("newpassword"); var confirm = document.getElementById("confirm_password"); if (password.value != confirm.value) { confirm.classList.add("errorinput"); document.getElementById("confirm-msg").classList.add("errormsg"); return false; } confirm.classList.remove("errorinput"); document.getElementById("confirm-msg").classList.remove("errormsg"); return true; } function validate_password(minlength) { // Did the checks pass ? var status = true; // Target element var password = document.getElementById("newpassword"); // Check the length if (password.value.length < minlength) { status = false; document.getElementById("minlen").classList.add("errormsg"); } else document.getElementById("minlen").classList.remove("errormsg"); // Look for a digit if (/.*\d/.test(password.value) != true) { status = false; document.getElementById("digit").classList.add("errormsg"); } else document.getElementById("digit").classList.remove("errormsg"); // Look for a lowercase char if (/.*[a-z]/.test(password.value) != true) { status = false; document.getElementById("lower").classList.add("errormsg"); } else document.getElementById("lower").classList.remove("errormsg"); // Look for an uppercase char if (/.*[A-Z]/.test(password.value) != true) { status = false; document.getElementById("upper").classList.add("errormsg"); } else document.getElementById("upper").classList.remove("errormsg"); // Change the color of the inputbox if (status == false) password.classList.add("errorinput"); else password.classList.remove("errorinput"); return status; }