数码资讯
纯Javascript判断查询的日期是否为有效日期。
以下内容主要是JS代码介绍的,代码简洁,包含注释,欢迎有好的建议。 如下,当查询条件中包含的日期,如2012-3-4,无论输入的日期字符串查询之前,是一个有效的日期检查。 无功snapshot_createtime_begin = $(选择器+输入{名称= 'createtime_begin}),瓦
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
以下内容主要是JS代码介绍的,代码简洁,包含注释,欢迎有好的建议。
如下,当查询条件中包含的日期,如2012-3-4,无论输入的日期字符串查询之前,是一个有效的日期检查。
无功snapshot_createtime_begin = $(选择器+输入{名称= 'createtime_begin}),瓦迩()饰();
无功snapshot_createtime_end = $(选择器+输入{名称= 'createtime_end}),瓦迩()饰();
尝试{
判断是开始时间的有效日期。
如果(snapshot_createtime_begin!= 新的日期(snapshot_createtime_begin)。GetDate()!= snapshot_createtime_begin.match( / D { 0 } $ / g){ 0 }。取代( / / g,)){
抛出新的错误();
}
确定结束时间是有效日期。
如果(snapshot_createtime_end!= 新的日期(snapshot_createtime_end)。GetDate()!= snapshot_createtime_end.match( / D { 0 } $ / g){ 0 }。取代( / / g,)){
抛出新的错误();
}
如果(Date.parse(snapshot_createtime_begin)> Date.parse(snapshot_createtime_end)){
()开始日期不应超过结束日期!;
警告()开始日期不应超过结束日期!;
返回;
}
扩展(pageobj,{美元。
CreateTimeBegin:snapshot_createtime_begin,
CreateTimeEnd:snapshot_createtime_end,
});
initpagination();
} catch(e){
()请输入有效日期!)
警告()请输入有效日期!;
}
js决定年份的日期是否为有效日期。
(intyear IsDate函数,intmonth,intday){
如果(isnan(intyear)| | isnan(intmonth)| | isnan(intday))返回false;
如果(intmonth > 12 | | intmonth<1)返回false;
如果(intday31)返回false;
如果((intmonth = = 4 | | intmonth = = 6 | | intmonth = = 9 | | intmonth = = 11)(intday > 30))返回false;
如果(intmonth = = 2){
如果(intday > 29)返回false;
如果((((intyear % 100 = = 0)(intyear % 400!= 0))| |(intyear % 4!= 0))(intday > 28))返回false;
}
返回true;
}
以上代码是日期校验的有效性,希望对您有所帮助。
如下,当查询条件中包含的日期,如2012-3-4,无论输入的日期字符串查询之前,是一个有效的日期检查。
无功snapshot_createtime_begin = $(选择器+输入{名称= 'createtime_begin}),瓦迩()饰();
无功snapshot_createtime_end = $(选择器+输入{名称= 'createtime_end}),瓦迩()饰();
尝试{
判断是开始时间的有效日期。
如果(snapshot_createtime_begin!= 新的日期(snapshot_createtime_begin)。GetDate()!= snapshot_createtime_begin.match( / D { 0 } $ / g){ 0 }。取代( / / g,)){
抛出新的错误();
}
确定结束时间是有效日期。
如果(snapshot_createtime_end!= 新的日期(snapshot_createtime_end)。GetDate()!= snapshot_createtime_end.match( / D { 0 } $ / g){ 0 }。取代( / / g,)){
抛出新的错误();
}
如果(Date.parse(snapshot_createtime_begin)> Date.parse(snapshot_createtime_end)){
()开始日期不应超过结束日期!;
警告()开始日期不应超过结束日期!;
返回;
}
扩展(pageobj,{美元。
CreateTimeBegin:snapshot_createtime_begin,
CreateTimeEnd:snapshot_createtime_end,
});
initpagination();
} catch(e){
()请输入有效日期!)
警告()请输入有效日期!;
}
js决定年份的日期是否为有效日期。
(intyear IsDate函数,intmonth,intday){
如果(isnan(intyear)| | isnan(intmonth)| | isnan(intday))返回false;
如果(intmonth > 12 | | intmonth<1)返回false;
如果(intday31)返回false;
如果((intmonth = = 4 | | intmonth = = 6 | | intmonth = = 9 | | intmonth = = 11)(intday > 30))返回false;
如果(intmonth = = 2){
如果(intday > 29)返回false;
如果((((intyear % 100 = = 0)(intyear % 400!= 0))| |(intyear % 4!= 0))(intday > 28))返回false;
}
返回true;
}
以上代码是日期校验的有效性,希望对您有所帮助。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。