String.prototype.mytrim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.myLTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.myRTrim = function()
{
return this.replace(/(\s*$)/g, "");
}
function checkSubmit(){
var beginTime =document.getElementById("beginTime").value.mytrim();
var endTime =document.getElementById("endTime").value.mytrim();
//输入的日期格式:2009-08-12/14:52
var pattern = /^((\d{2}(([02468][048])|([13579][26]))\-((((0[13578])|(1[02]))\-((0[1-9])|([1-2][0-9])|(3[01])))|(((0[469])|(11))\-((0[1-9])|([1-2][0-9])|(30)))|(02\-((0[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))\-((((0[13578])|(1[02]))\-((0[1-9])|([1-2][0-9])|(3[01])))|(((0[469])|(11))\-((0[1-9])|([1-2][0-9])|(30)))|(02\-((0[1-9])|(1[0-9])|(2[0-8]))))))(\/(((0[0-9])|(2[0-3])|(1[0-9]))\:([0-5][0-9])))?$/;
//对开始时间进行验证
if(beginTime == "") {
alert("开始时间不能为空");
return false;
}
if(!pattern.exec(beginTime))
{
alert('请输入正确的开始时间');
return false;
}
//对结束时间进行验证
if(endTime == "") {
alert("结束时间不能为空");
return false;
}
if(!pattern.exec(endTime))
{
alert('请输入正确的结束时间');
return false;
}
责任编辑:小草