javascript - 使用 Formik 反应验证最大范围
问题描述
我正在尝试使用 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");
推荐阅读
- xaml - MediaElement 不显示视频
- python - 压缩坐标然后访问它们
- ethereum - 未捕获的类型错误:Healthcenter.methods.getPatient 不是函数
- mongodb - MongoDB - 选择文档进行更新 - 选择后没有其他操作修改同一文档
- javascript - Azure 通过 javascript 获取访问令牌
- google-sheets - 非布尔逻辑 OR 运算符
- swift - 单击登录按钮时出现线程错误,该按钮应将视图移动到另一个主视图控制器,但在运行时获取线程
- python - 如何使用 OpenCV 阅读此视频?
- kubernetes - 可以将服务链接到具有不同图像的 pod 吗?
- python - 是否可以组合多个 .stl 文件以形成 3d 对象?