const validationSchema = yup.object({
amount: yup.number().positive().min(5, 'minimum 5').max(10, 'maximum 10'),
});
How is possible to add validation for decimal with two digits after ma?
const validationSchema = yup.object({
amount: yup.number().positive().min(5, 'minimum 5').max(10, 'maximum 10'),
});
How is possible to add validation for decimal with two digits after ma?
Share Improve this question asked Mar 29, 2022 at 9:41 AlexAlex 9,74030 gold badges107 silver badges166 bronze badges1 Answer
Reset to default 5solved like this:
let patternTwoDigisAfterComma = /^\d+(\.\d{0,2})?$/;
const monStringValidator = yup
.number()
.positive()
.test(
"is-decimal",
"The amount should be a decimal with maximum two digits after ma",
(val: any) => {
if (val != undefined) {
return patternTwoDigisAfterComma.test(val);
}
return true;
}
)
.min(5, "minimum 5")
.max(10, "maximum 10")
.required("Is required");
const validationSchema = yup.object({
amount: monStringValidator,
});