用户登录
用户注册

分享至

使用Formik的Reaction验证最大范围

  • 作者: 哇偶丶Sugar
  • 来源: 51数据库
  • 2022-10-19

问题描述

我正在尝试使用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");

;
软件
前端设计
程序设计
Java相关