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

183
Visualizações
Set minimum length restriction to Password Validation - Regular Expression

I have a regular expression for validating passwords.

/[\w\d]*(([0-9]+.*[A-Za-z]+.*)|[A-Za-z]+.*([0-9]+.*))/

This regex matches any words which contain letters and numbers in them.

I want to add a minimum length restriction as well, I got to know we can use {4,} to add a minimum length of 4.

But I am not able to figure out how to add this minimum length to the whole expression.

For example: The above regex matches p12 as valid.

I dont want it to match words with letters and numbers with a length of less than 4.

I tried this, but this did not work

/[\w\d]*(([0-9]+.*[A-Za-z]+.*)|[A-Za-z]+.*([0-9]+.*)){4,}/

Any help with respect to adding minimum length restriction to the whole expression would be appriciated.

Thank you.

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

0

Using \w also matches \d so this parts [\w\d]* can be written as just \w*

If you want to match only word characters, you could use for example 2 assertions for the char a-z and a digit.

Using a case insensitive pattern:

/^(?=[^\d\n]*\d)(?=[^a-z\n]*[a-z])\w{4,}$/i

Regex demo

const regex = /^(?=[^\d\n]*\d)(?=[^a-z\n]*[a-z])\w{4,}$/;
[
  "p12",
  "1234",
  "abcs",
  "p123"
].forEach(s => console.log(`${s} --> ${regex.test(s)}`));

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