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

190
Visualizações
How to check if a string contains at least one letter in JavaScript?

I am on validation work. this is my code

if (pwd.match(/[A-Za-z]/)) {
      $("#pwd-complexity-letter").html(good); 
      console.log("pwd complexity  invoked");
}

but this code has checked every string that I am passing through 'pwd'. For example, if I pass numbers or special char code become invoked and satisfying my input has at least one letter. how can I solve this please help. the problem is still on the small letter [a-z] checking. Capital letter only satisfy capital inputs. but the small letter has passed every string.

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

0

For this you can use javascript regexp

var regexp = /^[a-z]+$/i;
if (regexp.test(pwd)) {
  $("#pwd-complexity-letter").html(good); 
  console.log("pwd complexity  invoked");
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use regexp for it:

[a-z] will match any letter from a to z while /i will tell the regex to be case insensitive.

if (isPasswordValid("a1235@")) {
  console.log("Password valid")
} else {
  console.log("Password invalid")
};


function isPasswordValid(psw) {
  let regex = /^[a-z]/i
  return regex.test(psw) // you test if the passed string match the regex, if it does the function will return true else false.
}

You can use a function like isPasswordValid and pass your psw value in it to check if it's valid or not

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