问题
I need to get the validation using Formik that input should only be currentYear and up.
const currentYear = new Date().getFullYear();
expiryYear: yup
.string()
.required('Select expiry year')
.min(4, `Invalid year format (Example: ${currentYear + 4})`)
.max(4, `Invalid year format (Example: ${currentYear + 4})`)
.when('startDate', (currentYear, schema) => currentYear && schema.min(currentYear)),
回答1:
Try this please:
yup.date()
.min(new Date().getFullYear(),
'Year must be current year or greater than current year');
Check the demo
来源:https://stackoverflow.com/questions/62624939/get-formik-validation-current-year-and-up