Validate password size

Asked

Viewed 255 times

0

People because this condition doesn’t work?? It’s something simple but because I don’t know javascript I’m picking up.

function QTDsenha(){
  var senha = document.getElementById('idSenha');
    if(senha.value < 6){
        alert('Informe uma senha com no mínimo 6 caracteres');
    }    
}
<output>Senha<output>
<input id="idSenha" onblur="return QTDsenha()">

1 answer

2


'Cause you missed the size .length country:

function QTDsenha(){
  var senha = document.getElementById('idSenha');
    if(senha.value.length < 6){
        alert('Informe uma senha com no mínimo 6 caracteres');
        return false;
    }
}
<output>Senha<output>
<input id="idSenha" onblur="return QTDsenha()">

  • So if I understood correctly, value is like the string and length is for calculating the size of the string. That’s it?

  • @Luansilva That’s right.

  • function QTDsenha(){&#xA;document.getElementById('idSenha').value.length < 6 ? alert('Informe uma senha com no mínimo 6 caracteres') : ''; &#xA;}

  • 1

    Do trim() in password? This I found strange. Would not like my super secret password "pizza de bacon " could be broken by someone who knew I like bacon pizza

Browser other questions tagged

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