const validationSchema = yup.object({
amount: yup.number().positive().min(5, 'minimum 5').max(10, 'maximum 10'),
});
如何添加对逗号后两位数字的小数的验证?
像这样解决:
let patternTwoDigisAfterComma = /^\d+(\.\d{0,2})?$/;
const commonStringValidator = yup
.number()
.positive()
.test(
"is-decimal",
"The amount should be a decimal with maximum two digits after comma",
(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: commonStringValidator,
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)