Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!