我正在尝试使用 React 和 Formik 进行验证。我想要实现最大数字仅为 2,最大范围应仅为 12。
expiryMonth: yup.string().required('Select month').max(2, 'Invalid month format (Example: 06)'),
你可以使用这个:
yup.string()
.required("Select month")
.min(2, "Invalid month format (Example: 06)")
.max(2, "Invalid month format (Example: 06)")
.matches(/^(0?[1-9]|1[012])$/, "Month must be greater than 0 and can't be exceeded 12");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)