var password = document.getElementById("password") repassword = document.getElementById("repassword"); function validatePassword(){ if(password.value != repassword.value) { repassword.setCustomValidity("Captcha not match"); } else { repassword.setCustomValidity(''); } } password.onchange = validatePassword; repassword.onkeyup = validatePassword;