4
I am using the code that tells me if both emails are identical, if both passwords are identical and if they are at least 8 and at most 10 characters long. And only if the emails were equal, passwords equal and in the correct size does the form sign up button appear.
But how did I manage to use only the keyup
in the email2
and senha2
, if the user comes back and enters something in the password or email, does not change to error the input
.
What I wanted to know was how to put the same event with the same rules keyup
of email2
and senha2
also in the email
and senha
, to be validated in both confirmation fields.
And note that I haven’t even been able to restrict and validate the email, only whether or not they are identical.
$('#email2').on('keyup', function () {
var email = $("#email").val();
var email2 = $("#email2").val();
if (email != email2) {
$("#message").html("Os email não são identicos").css('color', 'red');
$('#validator').prop('disabled' , true);
} else {
$("#message").html("Os email são identicos").css('color', 'green');
$('#validator').prop('disabled' , true);
}
$('#validator').prop('disabled' , true);
$('#senha2').on('keyup', function (){
var password = $("#senha").val();
var confirmPassword = $("#senha2").val();
if (password.length < 8 || password.length > 16) {
$("#divCheckPassword2").html("As senhas precisam ter no minimo 8 caracteres e no máximo 16").css('color', 'red');
$('#validator').prop('disabled' , true);
} else {
$("#divCheckPassword2").html("").css('color', 'green');
$('#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' , true);
}
if (password != confirmPassword || password.length < 8 ||
password.length > 16 || email != email2){
$('#validator').prop('disabled' , true);
} else {
$('#validator').prop('disabled' , false);
}
})
});
Thanks friend, but now it does not validate the password, even if it has more than 8 characters and are identical, for everything in the error part of passwords
– Mauricio Kalfelz
right gave perfect, more like validate now this part with it
code
Function validar(){ if (email != Email2.val() || password.val().length < 8 || password.val().length > 16 || password.val() != password2.val()){ $('#Validator'). prop('disabled', true); }Else { $('#Validator'). prop('disabled' , false); } }code
– Mauricio Kalfelz
I didn’t touch the validation part, just the events, copy its validation, but anyway, I’ll change it :)
– Wictor Chaves
I can only thank your help friend
– Mauricio Kalfelz
I edited and now this working validation
– Wictor Chaves
thank you very much friend, saved my life
– Mauricio Kalfelz
@Sam, I put "separate" taking into account the original code, where he put a keyup inside another keyup.
– Wictor Chaves