Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda