JS time verification source code
(1) a short time, such as (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 in the timeformat '); Return false ;}
If (A [1]> 24 | A [3]> 60 | A [4]> 60)
{
Alert ("Time Format incorrect ");
Return false
}
Return true;
}
(2) Short date, such as (2003-12-05)
function strdatetime (STR)
{< br> var r = Str. match (/^ (\ D {}) (-| \/) (\ D {}) \ 2 (\ D {}) $ /);
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, for example (13:04:06)
function strdatetime (STR)
{< br> var Reg =/^ (\ D {}) (-| \/) (\ D }) \ 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]);
}