Search this blog

Showing posts with label Regular-Expressions. Show all posts
Showing posts with label Regular-Expressions. Show all posts

Wednesday, June 24, 2009

JavaScript - Regular Expressions for Validate 24 Hrs Time

One of my friend requested me a code of Javascript to validate the time, which is in the format of 00:00 (24 hrs). i written this code. it may useful to someone, so that i posted in this blog

function Validate24Hrs(Time_Field) {

RegEx = "\([0-2][0-9]):([0-5][0-9])$";

Err_Msg = "";

if (Time_Field.value != "")

{

if (Regs = Time_Field.value.match(RegEx)) {

if ((Regs[1] > 23)) {

Err_Msg = 'Not Matching';

}

}

else {

Err_Msg = 'Not Matching';

}

}

if (Err_Msg != "") {

alert(Err_Msg);

Time_Field.focus();

return false;

}

else {

alert('Matching');

return true;

}

}


if it is useful or face any problem, please leave ur valuable comments here.

Have a Great Day!