Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  141] [ 3]  / answers: 1 / hits: 27454  / 12 Years ago, mon, august 13, 2012, 12:00:00

I want to validate 24 hour formatted Time, Time is in the following format.



HH:MM:SS


How could i go for it. Please help me.
My HTMl Code is



    <asp:TextBox Width=120px MaxLength=20 ID=txtEndTime runat=server></asp:TextBox>
<ajaxctrl:maskededitextender id=metxtEndTime runat=server targetcontrolid=txtEndTime
mask=99:99:99 messagevalidatortip=true masktype=Number inputdirection=LeftToRight
clearmaskonlostfocus=false acceptnegative=None errortooltipenabled=True />

More From » jquery

 Answers
7

To only validate the format, you can use this:



var valid = (timeStr.search(/^d{2}:d{2}:d{2}$/) != -1);


If you're trying to validate the values as well, you can try this:



var valid = (timeStr.search(/^d{2}:d{2}:d{2}$/) != -1) &&
(timeStr.substr(0,2) >= 0 && timeStr.substr(0,2) <= 24) &&
(timeStr.substr(3,2) >= 0 && timeStr.substr(3,2) <= 59) &&
(timeStr.substr(6,2) >= 0 && timeStr.substr(6,2) <= 59);

[#83679] Saturday, August 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mahogany

Total Points: 645
Total Questions: 107
Total Answers: 98

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;