0
I have a function validaSenha
that I’m using that checks the amount of characters and returns true
or false
.
In the action of the end button I execute a call in the function inside a if
, but even validating does not issue the alert.
Debugging, I put one alert(validaSenha($("#senha").val()))
, and is returning correctly.
Someone could help me in this case?
$("#btn-finalizar").on('click', function(e) {
e.preventDefault();
if ( validaSenha($("#senha").val()) )
alert('ok')
})
function validaSenha(senha) {
var numeros = 0;
var letras = 0;
var caracteres = senha.split('');
for (let car of caracteres) {
if (car.match(/\d/)) numeros++; // se for numero
else if (car.match(/\w/)) letras++; // se não for numero, pode ser letra
}
return (numeros+letras) >= 8 && (numeros + letras) == senha.length;
}
I tested it here and it worked, are you sure it’s not a typo? You have how to put the html used?
– Denis Rudnei de Souza
@Denis Rudnei de Souza I think the problem was with characters that are neither letters nor numbers.
– PauloHDSousa