Yup: How to check for big integer number?

Created on 30 May 2019  路  2Comments  路  Source: jquense/yup

.number().integer() doesn't work for 2147483647 and higher. How to check, that the number is integer with more numbers (not a float, without a decimal point etc)?

Most helpful comment

You can write custom test making it a number

Yup.number("Enter a valid number")
        .test("int", "Must be integer", val => {
          return val % 1 == 0;
        });

All 2 comments

yup doesn't cover that since javascript doesn't (until super recently) handle anything larger than a 32bit int. We could theoretically fallback to BitInt if the current environment handles that but thats like only really modern browsers

You can write custom test making it a number

Yup.number("Enter a valid number")
        .test("int", "Must be integer", val => {
          return val % 1 == 0;
        });
Was this page helpful?
0 / 5 - 0 ratings