Real-time password verification with javascript and html

Asked

Viewed 1,940 times

2

Good night

I would like a help of what would be a real-time password check in javascript and html, I think of two text boxes and a message below that would indicate something like "divergent password" until the two 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>

Thank you for reading!

  • Voce can use patern and the required field only patern in safari does not work yet dai Voce would have to use also javascript

  • put html code there that I design for you

  • Assanges help me please!

  • Face your function validateNew() this correct is only with some syntax errors but Do you want the end to display a friendly message instead of an Alert and that? does not understand right your question yet @Vitor Marques

  • What I wanted is that I did not need to press the "Validate" button to identify if the two fields are equal, this check would be being done at all times in real time.

  • you can take this Lert, as a feedback could be a text in the same form, if you help me will help me very expensive, I spent hours trying to do this, I am layman in the subject yet...

  • mano finished the cafe around here but stay there in the show for sure someone will help you abs

Show 2 more comments

1 answer

1

You can put something like, I don’t remember very well how it does, because it had done with jquery. But anything if it doesn’t work, I edit it right here. Blz? It also has some codes ready that Voce finds in the internet that makes the checks bunitinho and such. I hope to contribute in 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>
  • Cool! It’s very elementary, I will be able to adapt your code easily, the feedback is the border color change right?

  • Assanges, this function onKeypress, you know if I impute a text in the textbox via code, know if it will identify the change?

  • That, I believe I would not identify, because it detects the keystroke, for change unless I mistake is onChange=

  • Localhost Unfortunately the onChange and onKeypress function require keyboard pressing, if I print a text in the textbox the code does not notice the change and the function is not executed

Browser other questions tagged

You are not signed in. Login or sign up in order to post.