1. Short time, shape (13:04:06)
function Istime (str)
{
var a = Str.match (/^ (\d{1,2}) (:)? ( \d{1,2}) \2 (\d{1,2}) $/);
if (a = = null) {alert (' input parameter is not a time format '); return false;}
if (a[1]>24 | | a[3]>60 | | a[4]>60)
{
Alert ("The time format is incorrect");
return False
}
return true;
}
2. Short date, shaped like (2003-12-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]);
}
3. Long time, shape (2003-12-05 13:04:06)
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]);
}
JavaScript Validation time format