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

222
Visualizações
validate password from user input after clicking submit button

I want it to check if the user entered the correct format for the password (which is at least one lowercase, one uppercase, one number, eight or more characters, and one special character) but I couldn't get it to validate.

JS:

var Pass = document.getElementById('password');
function validatePassword() {
  if (Pass.value.match(/^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,}$/)) {
    document.getElementById('pass').innerHTML =
      'Invalid password. Please follow the format.';
    return false;
  }
}

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

adding more expression will help. for checking the cap and small letters. Also for checking the password, you need some sort of button to use it as a trigger to call the function.

or u can use "oninput" event listener.

var Pass = document.getElementById('password');
// lets say your validator button hase id of validate;
let validator=document.getElementById("validate");
validator.onclick=validatePassword(Pass.value);
// or use on input method like
Pass.oninput=validatePassword(Pass.value);
function validatePassword(value) {
let reg=/^(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9!@#$%^&*]{8,}$/;
  if (!reg.test(value) {
    Pass.innerHTML =
      'Invalid password. Please follow the format.';
    return false;
  }
return true;
}
about 4 years ago · Santiago Trujillo 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