Real-time password verification with javascript and html

2

Good evening

I would like a help from what a real-time password verification in javascript and html would look like, I think of two text boxes and a message below that would indicate something like "divergent password" until both fields are filled with the same value , one or example would help me a lot!

<html>
    <head>
        <title>Validade Senha</title>
    <script> function validarSenha(){
        senha1 = document.f1.senha1.value
        senha2 = document.f1.senha2.value
        if (senha1 == senha2) alert("SENHAS IGUAIS")
        else alert("SENHAS DIFERENTES") }
    </script>
    </head>
<body> VALIDAR SENHA <br> <br>
    <form action="" name="f1">
    Senha: <input type="password" name="senha1" size="20"> <br>
    Confirmar Senha: <input type="password" name="senha2" size="20"> <br>
    <input type="button" value="Validar" onClick="validarSenha()">
    </form>
</body>
</html>

Thanks for reading!

    
asked by anonymous 23.06.2016 / 05:29

1 answer

1

You can put something of the type, do not remember very well how it does, because it had done with jquery. But if I do not, I'll edit it here and put it right. OK? It also has some codes that you can find on the internet that makes the verifications little bunny and such. I hope to contribute something

  <input type="text" id="pass" onKeyPress="Verifica()"/>
<input type="text" id="pass2"  onKeyPress="Verifica()"/>
<script>
function Verifica(){
    val1=document.getElementById("pass").value;
    val2=document.getElementById("pass2").value;
    if(val1!=val2){
    document.getElementById("pass").style.borderColor="#f00";
        document.getElementById("pass2").style.borderColor="#f00";
    }
    else{document.getElementById("pass").style.borderColor="#000";
        document.getElementById("pass2").style.borderColor="#000";

        }
    }
</script>
    
23.06.2016 / 05:53