javascript - 如何使用 yup 验证输入的日期是今天还是未来
问题描述
这适用于除同一天以外的所有情况,
Yup.date()
.required(“Start Date is required”)
.test(“startDate”, “Start Date can not be a passed Date”, function (date) {
const cutoff = new Date();
const selectedDate = date;
return selectedDate >= cutoff;
}),
解决方案
与其现在使用获取日期/时间new Date()
,不如将其时间设置为今天的开始:
const cutoff = new Date();
cutoff.setHours(0, 0, 0, 0);
推荐阅读
- android - AnchorNode/Models 在 android sceneform sdk 中消失了
- terraform - 如何将 LogDNA 或 SysDig 实例标记为平台日志或指标的默认目标?
- sql-server - MS Access VBA将SQL中的字符串解释为int?
- python - Django 创建唯一的外键对象
- x86 - Skylake中干净缓存行的写回?
- java - Flyway:无需迁移
- javascript - 节点脚本无法完成
- python-3.x - 如何使用 python 与控制台应用程序交互?
- javascript - 如何基于 es5/es2015 浏览器支持预取 javascript 文件
- spring-boot - 如何从单元测试中连接@Configuration 文件 - Spring Boot + Kotlin