问题描述
我正在尝试使用Reaction和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");;