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

202
Visualizações
How to check the sting is alphanumeric or not in peggyjs

I want to check the given string is alphanumeric or not. i.e. the expected output is as follows

  • 123 should retun false
  • abc should retun false
  • a123 should retun true
  • 1a23 should retun true

I tried with the ^[a-zA-Z0-9]*$ regex. It is not working as expected. Can anyone suggest the working peggyjs regex? Thanks.

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

0

You can assert not only digits, and match at least a single digit restricticting to match to only a-z or a digit.

Using a case insensitive match:

^(?!\d+$)[a-z]*\d[a-z\d]*$

Regex demo

about 4 years ago · Juan Pablo Isaza Relatório

0

If you know the order (letters then numbers for example) you can do .*[a-zA-Z].*[0-9]

But I assume you can't make such assumptions so I would use the slightly more complex ^(?=.*[a-zA-Z])(?=.*[0-9]).* which means "a letter somewhere later, and also a number somewhere later".

PS : you can replace all [0-9] by \d if you like.

Edit : that's only assuming you don't get other kinds of characters, use Alireza's regex instead if you need to.

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