javascript - 确定日期字段是 NaN 还是空
问题描述
我提供以下代码供审查:
//THIS VALIDATES THE DATE ENTERED
var cMsg = "The date you entered is invalid.\n\nPlease enter a date that does not pre-date the previous entry date.";
var nIcon = 0;
var nType = 0;
var cTitle = "DATE ERROR";
var str = event.target.name;
var res = str.charAt(str.length-1);
var d1 = Date.parse(this.getField("0." + (res-1)).value);
var d2 = Date.parse(event.value);
if(d1 != null) {
if (d1 > d2) {
app.beep();
app.alert(cMsg, nIcon, nType, cTitle);
event.value = "";
}
} else {
var cMsg = "This is an invalid entry\n\nThe previous date entry cannot be empty.\n\nPlease use the entry above first.";
app.beep();
app.alert(cMsg, nIcon, nType, cTitle);
}
规则:
- d2 不能(或不应该)是早于 d1 的日期
- d2 不能(或不应该)被填充,除非首先填充 d1
也许不是不允许输入(严格执行),我们只是提醒用户并确认他们希望继续,即使违反了预期的规则......这可能会更好。
这对我来说很困难。可以的话请帮忙。
解决方案
推荐阅读
- jenkins - 获取 $BRANCH_NAME 并将其分配给 Jenkinsfile 中的环境变量
- javascript - 为什么什么都没有显示?
- selenium - 如何通过 Safari 浏览器和 selenium-webdriver 将文本发送到网页中的用户名和密码字段
- gridview - DotVVM - GridView 绑定
- java - Wildfly 服务器未连接但已启动然后超时
- c# - 来自具有多个等待的异步函数的 DB 中的空白值
- airflow - Airflow 1.10 Config Core hostname_callable - 如何设置?
- ruby-on-rails - XXX 的副本已从模块中删除,但仍处于活动状态
- php - 自动更改日期字段的格式(Laravel)
- javascript - 初始加载时禁用按钮,提交后启用