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

198
Visualizações
How to don't allow set only the same characters and only special sign - regex js

I'm looking for some regex pattern to:

  • not allow set the same characters
  • not allow only special signs.

So:

  • 11111111 - not allow
  • 1111811111 - allow
  • rrrrrrrr - not allow
  • rrrrrrrrrr5 - allow
  • 11111111% - allow
  • %$!@$!@@@@ - not allow
  • %%%%%%%%%1 - allow

I found regex which is helpful for recognize that string has only special sign: /^\W*\w.*$/, but I don't know how to join it with condition about not only repeated characters. Thansks for any advices.

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

0

You can assert not only the same characters and make sure to match at least a single word character.

^(?!(.)\1+$)[^\w\n]*\w.*$

Explanation

  • ^ Start of string
  • (?!(.)\1+$) Negative lookahead, assert not only the same characters in the string matching at least 2 characters
  • [^\w\n]* Optionally match any character except a word character or newline
  • \w Match at least a single word character
  • .* Optionally match any character
  • $ End of string

Regex demo

const regex = /^(?!(.)\1+$)[^\w\n]*\w.*$/;
[
  "11111111",
  "1111811111",
  "rrrrrrrr",
  "rrrrrrrrrr5",
  "11111111%",
  "%$!@$!@@@@",
  "%%%%%%%%%1",
  "a"
].forEach(s => {
  if (regex.test(s)) {
    console.log(s + " allow")
  } else {
    console.log(s + " not allow")
  }
});


If you don't want to match any spaces in the string, you can match non whitespace chars using \S

^(?!(\S)\1+$)[^\w\s]*\w\S*$

Regex demo

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