function checkDateTime(date){
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = date.match(reg);
if(r == null){
alert("输入格式不正确,请按yyyy-MM-dd HH:mm:ss的格式输入!");
return false;
}else{
return true;
}
}
验证短日期(2007-06-05)
function strDateTime(str)
{
var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false;
var d= new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
验证长日期(2007-06-05 10:57:10)
function strDateTime(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
验证时间(10:57:10)
function isTime(str)
{
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert(’输入的参数不是时间格式’); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert("时间格式不对");
return false
}
return true;
}
比较两个日期大小
function compareDate(d1,d2)
{
return ((new Date(d1.replace(/-/g,"\/"))) < (new Date(d2.replace(/-/g,"\/"))));
}
function CheckTime()
{
var checkValue = new RegExp ("^\[0-2]{1}\[0-6]{1}:\[0-5]{1}\[0-9]{1}:\[0-5]{1}\[0-9]{1}") ;
var stControl = document.getElementById("txtStartTime") ;
var stValue = stControl.value ;
if (stValue == "")
{
alert("请填写开始时间") ;
return false ;
}
if (!(checkValue.test(stValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
var etControl = document.getElementById("txtEndTime") ;
var etValue = etControl.value ;
if (etValue == "")
{
alert("请填写结束时间") ;
return false ;
}
if (!(checkValue.test(etValue)))
{
alert("请填写公司内部规定时间") ;
return false ;
}
return true ;
}