我使用formik创建了一个数据选择器,我必须使用Yup进行验证。例句:如果我的年龄是18岁,将它与当前的日期进行比较,并且如果我将从日期选择器中选择一个超过18岁的日期,那么它应该会给我一条信息:您的年龄小于18岁。
发布于 2020-01-29 10:12:51
const YourSettingSchema = Yup.object().shape({
dateOfBirth: Yup.string()
.nullable()
.test('Date of Birth', 'Should be greather than 18', function(value) {
return moment().diff(moment(value), 'years') >= 18;
}),
});https://stackoverflow.com/questions/59926680
复制相似问题