email validation and password being equal and with minimum character

Asked

Viewed 232 times

0

hello, I’m starting in the world of jquery and I’m working with djando and python and the form has the jquery below

 <script>
 $('#validator').prop('disabled' , true);
 $('#senha2').on('keyup', function () {
 var password = $("#senha").val();
 var confirmPassword = $("#senha2").val();

 if (password != confirmPassword) {
     $("#divCheckPassword").html("As senhas não são").css('color', 'red');
     $('#validator').prop('disabled' , true);
 } else {
    $("#divCheckPassword").html("Senhas identicas").css('color', 'green');
    $('#validator').prop('disabled' , false);
 }
});
 </script>

and it works perfectly it only activates the form button if both emails have certain, but I need him to do it using email and tbm the iinpput of the password and to make matters worse I need it to be configured so that the password has at least 8 characters and at most 16 and that the email fields are considered equal only if the emails are validated. I wish it was being validated while typing

I think I really want to

2 answers

1

You can use HTML5 validations, for example:

<input type="text" name="password" maxlength="16" minLength="8">

<input type="email" name="email">

1


 if (password.length < 8 || password.length > 16) { 
     $('#validator').prop('disabled' , true);
 }     

if (password != confirmPassword) {
         $("#divCheckPassword").html("As senhas não são").css('color', 'red');
         $('#validator').prop('disabled' , true);
     } else {
        $("#divCheckPassword").html("Senhas identicas").css('color', 'green');
        $('#validator').prop('disabled' , false);
     }

Browser other questions tagged

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