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

188
Visualizações
Using Angular Validators to create a restriction of 6-12 characters, but NOT of length 9

I am trying to create a Angular Validator that allows me to validate a string of both letters and characters of lengths 6-12 inclusive, but not of length 9.

I have tried

RegexAlphaNumeric = "^[a-zA-Z0-9]{6,8}|[a-zA-Z0-9]{10,12}$";
userId: ['', [Validators.minLength(6), Validators.maxLength(12),Validators.pattern(this.RegexAlphaNumeric)],],

Wondering if my usage of minLength and maxLength should not be used here and if there is a way to just utilize Validators.pattern() for this method.

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

0

You could either use a negative lookahead to assert not 9 characters:

^(?![a-zA-Z0-9]{9}$)[a-zA-Z0-9]{6,12}$

See a regex101 demo.

Or use an alternation as you already have in your question, but you have to group the parts between the start and the end of the string or else the pattern would match either 6-8 chars from the start or 10-12 chars at the end only.

^(?:[a-zA-Z0-9]{6,8}|[a-zA-Z0-9]{10,12})$

See a regex101 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