Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda