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

234
Vistas
Validating an input that do not suppose to allow decimals, it accepts 0.0

I am validating an input type number, it only must accepts values from 0 to 9999. There can not be dots/decimals or anything like that. I am doing it in a hacky way but it still throws an error when you enter 0.0. The input can not receive any kind of special characters, only integer numbers from 0 to 9999.

// Initial value is an string
integersOnly(value) {
    // So I need to convert it to a number
    const turnValueIntoANumber = Number(value);
    return (isNaN(turnValueIntoANumber) || !Number.isInteger(turnValueIntoANumber)) && 'Only integers allowed';
}

The field:

<Field
    min={0}
    max={9999}
    name="time"
    type="number"
    validate={[this.integersOnly]}
>
    TIME
</Field>

What am I doing wrong?

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

0

i think you are using formik . what about using yup schema builder for validation. check this : yup documentation

you can use

yup.number().required().positive().integer()
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