1.如 (12:02:02)
2. 如 (2008-08-08)
3. 如 (2008-08-08 08:08:08)
function isTime(str)
{
var time = str.match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (time == null) {alert('输入的参数不是时间格式'); return false;}
if (time [1]>24 || time[3]>60 || time[4]>60)
{
alert("时间格式不对");
return false
}
return true;
}
2. 如 (2008-08-08)
function isDate(date)
{
var reg = date.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(reg==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]);
}
3. 如 (2008-08-08 08:08:08)
function isDateTime(dateTime)
{
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]);
}