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

138
Vistas
How to accept only number in the input field using js

How to make the input box accept only numbers in the input field using js event listener.

  <form action="#">
     <label for="value">Value:</label>
     <input type="text" name="value" id="value" />
     <button type="submit">Convert</button>
     <button type="reset">Clear</button>
  </form>
 

<script>
    form.addEventListener(`submit`, function(event){
        event.preventDefault();
    });    
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can parse the input to a number and then check if it is a number or something else like NaN.

if(typeof parseInt(input) ==="number"){
  console.log("number!");
}

Please note that anyone can bypass this using the dev tools so don't forget to implemnt server-side validation.(Thx for the tip @samathingamajig)

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