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

130
Visualizações
I would like to add numerical limits to this block of code
document.querySelectorAll('input').forEach(input => {
  input.addEventListener("keydown", function(e) {
    var charValue = String.fromCharCode(e.keyCode);
    if (((!/^(\d+)?([.]?\d{0,1})?$/.test(this.value + e.key)) && (e.which != 8))) {
      e.preventDefault()
    }
  })
})

SetPoint :<input id="input" type="text" name="setPoint"   max="5" min="1" />

this block of code is a bit beyond my understanding but I'm guessing you use e.something and <= in the if statement to add a less than or equal to limit the number that the form will accept

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

0

Everytime you type a letter in the keyboard, you got a specific e.keyCode or e.key. Try to debug the value of each variable to understand the code.

To put a limit simply do a check to prevent default behavior (prevent further typing)

var nextValue = this.value + e.key;
if (nextValue < 1 || nextValue > 5) {
    e.preventDefault()
}
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