Get Formik Validation Current Year and Up

天涯浪子 提交于 2020-06-29 03:37:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!