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

255
Visualizações
Can I get some assistance a regex issue?

I use javascript regex replacements at various places but I have come across something I can't quite get. I have an input box that will always be 10 characters. The first 2 characters will always be a capital letter and the other 8 will always be a number.

Using jQuery's keyup & replace functions (I do this with other regex replacements) I need invalid characters replaced with "" as they are typing. For instance, say the desired input is AB12345678 and while typing the 1st or 2nd character they either type a small letter, number, or other character, it is removed. Same with positions 3-10, if anything other than a number is typed, it gets removed.

As I said I have other spots where I do this but not for specific positions within the input, such as $(this).val($(this).val().replace(/\D/g, "")) only allows the entering of numbers in a box or $(this).val($(this).val().replace(/[^a-zA-Z0-9]+/g, "")) will only only allow upper/lower case letters and numbers.

Ideally I suppose with the first 2 characters if they type a lowercase letter it would get converted to uppercase but for now, will just remove it.

I am probably overlooking something simple for making sure the first 2 characters are entered with only capital letters and the last 8 are only numbers but....

about 4 years ago · Juan Pablo Isaza
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