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
Input[type="number"] handler not working properly [Formik, RegExp]

I have an input which can't have more than 2 decimal places. Also I have validation, which doesn't work properly for numbers with lots of zeros.

Expected behavior

Unexpected behavior

export default function App() {
  const isValidAmount = (amount) => /^$|^\d+\.?\d{0,2}$/.test(String(amount));

  return (
    <div>
      <Formik initialValues={{ decimalNumber: "" }}>
        {({ handleChange }) => (
          <Field
            className="input"
            type="number"
            name="decimalNumber"
            placeholder="Decimal Number"
            component={TextField}
            InputProps={{
              onChange: (e) => {
                if (!isValidAmount(e.target.value)) return;
                handleChange(e);
              }
            }}
          />
        )}
      </Formik>
    </div>
  );
}

Code here

Can you please explain: What is going on?

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

0

Use the HTML step attribute to limit the allowable numbers. In this case you want to limit to hundredths:

<Field
  /* ... */
  step="0.01"
/>
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