函数名:CheckDateTime
//功能介绍:检查是否为日期时间
functionCheckDateTime(str){
varreg=/^(\d+)-(\d{1,2})-(\d{1,2})(\d{1,2}):(\d{1,2}):(\d{1,2})$/;
varr=str.match(reg);
if(r==null)returnfalse;
r[2]=r[2]-1;
vard=newDate(r[1],r[2],r[3],r[4],r[5],r[6]);
if(d.getFullYear()!=r[1])returnfalse;
if(d.getMonth()!=r[2])returnfalse;
if(d.getDate()!=r[3])returnfalse;
if(d.getHours()!=r[4])returnfalse;
if(d.getMinutes()!=r[5])returnfalse;
if(d.getSeconds()!=r[6])returnfalse;
returntrue;
}
http://www.corange.cn/archives/2008/03/553.html
//功能介绍:检查是否为日期时间
functionCheckDateTime(str){
varreg=/^(\d+)-(\d{1,2})-(\d{1,2})(\d{1,2}):(\d{1,2}):(\d{1,2})$/;
varr=str.match(reg);
if(r==null)returnfalse;
r[2]=r[2]-1;
vard=newDate(r[1],r[2],r[3],r[4],r[5],r[6]);
if(d.getFullYear()!=r[1])returnfalse;
if(d.getMonth()!=r[2])returnfalse;
if(d.getDate()!=r[3])returnfalse;
if(d.getHours()!=r[4])returnfalse;
if(d.getMinutes()!=r[5])returnfalse;
if(d.getSeconds()!=r[6])returnfalse;
returntrue;
}
http://www.corange.cn/archives/2008/03/553.html
本文介绍了一个JavaScript函数CheckDateTime,用于验证字符串是否符合特定的日期时间格式,并确保其正确无误。该函数通过正则表达式匹配日期时间字符串,并使用Date对象进行详细校验。
1393

被折叠的 条评论
为什么被折叠?



