当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript检查日期格式的函数[比较全]

Javascript
提高网站信任度的技巧
javascript脚本编程解决考试分数统计问题
图片上传之前检查大小、尺寸、格式并预览的js代码
JavaScript打开客户端exe文件的代码
JavaScript confirm选择判断
javascript title闪动效果
javascript把15位身份证转成18的函数
新人报道,发个小技巧(js数组重复判断)
Javascript this关键字使用分析
javascript TextArea动态显示剩余字符
JavaScript Undefined,Null类型和NaN值区别
javascript Select标记中options操作方法集合
javascript trim 去空格函数实现代码
javascript网页关闭时提醒效果脚本
checkbox 多选框 联动实现代码
收集的比较全的automation服务器不能创建对象 异常原因和解决方法
Javascript客户端将指定区域导出到Word、Excel的代码
IE浏览器兼容Firefox的JS脚本的代码
在html页面中包含共享页面的方法
javascript replace()用法详解附实例代码

Javascript 中的 javascript检查日期格式的函数[比较全]


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 133 ::
收藏到网摘: n/a

非常全的,功能较多的日期检查函数 //用于日期的文本框 name = "indate"
function check1(Form)
{
for (i = 0; i < Form.length; i++)
{
if (Form.elements[i].value == "")
{
alert("请填写完整!")
Form.elements[i].focus();
return;
}
if (Form.elements[i].name == "indate")
{
var date = Form.elements[i].value;
len = date.length;
var datearray = date.split("-")
//alert(datearray[1]);
var year = parseInt(datearray[0]);
var month = parseInt(datearray[1]);
var day = parseInt(datearray[2]);
if (len == "")
{
alert("时间不能为空");
return;
}
else if (len > 10)
{
alert("日期格式不正确");
return;
}
else if (isNaN(year))
{
alert("日期格式不正确");
return;
}
else if ((year > 9999) || (year < 100))
{
alert("日期格式不正确");
return;
}
else if (isNaN(month))
{
alert("日期格式不正确");
return;
}
else if ((month > 12) || (month < 1))
{
alert("日期格式不正确");
return;
}
else if (isNaN(day))
{
alert("日期格式不正确");
return;
}
else
{
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if ((dat < 0) || (day > 31))
{
alert("日期格式不正确");
return;
}
break;
case 4:
case 6:
case 9:
case 11:
if ((day < 0) || (day > 30))
{
alert("日期格式不正确");
return;
}
break;
default:
if ((year % 100 == 0) && (year % 4 == 0))
{
if ((day < 0) || (day > 29))
{
alert("日期格式不正确");
return;
}
}
else
{
if ((day < 0) || (day > 28))
{
alert("日期格式不正确");
return;
}
}
}
}
}
}
Form.submit();
}