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

100
Vistas
How to prevent input field from typing numbers on Firefox

I have a bug in my application. It's a currency converting app - and it should only accept numbers.

I wrote an application that takes numbers from input. It works perfectly fine on Chrome, but firefox allows me/user to type in any character. I tried all kinds of methods, and functions to prevent this behavior - such as regex functions with tests to see if e.target.value is a number or not, pattern="[0-9]", inputype='numeric' and a few more.

<input type="number" onChange={e => setFromTo(e.target.value)} />

Does anybody know how to prevent firefox input field from accepting any character, and only taking in numbers?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try adding this line in your input field

onKeyPress={(event) => {(!/[0-9]/.test(event.key)) {
                            event.preventDefault();
                          }
                        }}
about 4 years ago · Juan Pablo Isaza Denunciar

0

try adding this to your input tag.

oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');"
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