I have a project in which I have to add a registration form and I want to to validate that the password and confirm fields are equal without clicking the register button.
I think this example is good to check https://codepen.io/diegoleme/pen/surIK
I can quote code here
and
var password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;