Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
Validation different message on the condition in password?

Hi I would like some help on my password field where I have these 2 types of validation messages:

first, if the input for the password when user clicks on submit button it displays please enter password!

2nd if the input for the password is incorrect where it didn't meet the requirement it displays password does not meet the requirement!

Here my code for my html for the password and submit button

<div class="form-group row">
  <label for="validationpassword" class="col-form-label passwordadduser">*Password:</label>
  <div class="col-6 d-flex">
    <input name="validationpassword" onChange="onChange()" type="password" class="form-control pass" id="password" placeholder="Password"  required>
    <i class="bi bi-eye-slash" id="togglePassword"></i>
    <div style="margin-left: 15px;" class="invalid-tooltip password-empty" hidden>
      Enter a password!
    </div>
    <div style="margin-left: 15px;" class="invalid-tooltip password-notmeet" hidden>
      Password do not meet the requirement!
    </div>
  </div>
</div>

<button type="submit" class="btn-primary submitbutton">Add</button>

I have try a Jquery/JavaScript but seems not working i think i doing something wrong here

var empty = $(document.getElementById("password").value == '')
if (empty){
  $('.pass').removeAttr('hidden');
}
else{
  $('.pass').attr('hidden', '');
}

needed help as I am not familiar with how the input should work?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I had checked your code and it seams that que js/jquery part its not complete. Also theres a function call in the input while something is beeing written into the input that it's missing in your js code so the console throw an error everytime the input text is changed. A part from that, I had made some changes to your code so, if i understood well, it should make what you asking for

html:

<div class="form-group row">
   <label for="validationpassword" class="col-form-label passwordadduser">*Password:</label>
   <div class="col-6 d-flex">
      <input name="validationpassword" onChange="onChange()" type="password" class="form-control pass" id="password" placeholder="Password"  required>
      <i class="bi bi-eye-slash" id="togglePassword"></i>
      <div style="margin-left: 15px; display: none;" class="invalid-tooltip password-empty">
         Enter a password!
      </div>
      <div style="margin-left: 15px; display: none;" class="invalid-tooltip password-notmeet">
         Password do not meet the requirement!
      </div>
   </div>
</div>
<button class="btn-primary submitbutton" id="submitbutton">Add</button>

js/jquery (rember always import jquery library before executing your js code):

$('#submitbutton').click(function() {
    var passwordInput = $('#password')
    //Empty password validation
    if (passwordInput.val() == '') {
        $('.password-notmeet').hide();
        $('.password-empty').show();
        return;
    }
    //Any other requirements (ex: passwd length)
    if (passwordInput.val().length < 6) {
        $('.password-empty').hide();
        $('.password-notmeet').show();
        return;
    }
    //more code
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda