Search this blog

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!

5 comments:

  1. Super Babu for u r code,it is very much useful for our application
    Thanks once again

    ReplyDelete
  2. Suresh! Thanks for your valuable comments

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete