Here is a time checker example:
<script id="time checking function">
function isTime(objTbox,blnCanBeNull,strControl,strErrLabel,blnRange,strMin,strMax,strTimeFormat) {
// objTbox: is the textbox that contains the value that needs to be checked you
// can pass this using the following command: document.getElementById('textboxid')
// bnlCanBeNull: if this value is true than the textbox can be empty if it is false the textbox cannot be empty
// strControl: This is the name of how the user preceives the textbox for example:
// starttime: **some textbox*** The user will see the textbox as starttime
// because the text starttime is before the textbox
// strErrLabel: This is the label where the errormessage wil be displayed
// blnRange: This is true if the time needs to be in a certain range
// for instance between 8:00 and 22:00
// strMin If the time needs to be in a certain range than strMin is the
// minimum vale for example a time between 8:00 and 22:00 the 8:00
// wil be the minimum value !!!IN STRMIN THE : IS LEFT OUT AND IT NEEDS TO BE 4 CHARACTERS LONG!!!
// so in this example you have to specify strMin as 0800
// strMax If the time needs to be in a certain range than strMax is the
// maximum time, given the example used in strMin strMax wil be 2200
// strTimeFormat: This is the format of the time, if you need a pm/am time format you
// have to provide a string "pm/am". If it is empty a 24 hour timeformat
// is used
var str24H = "";
var strTimeSuffix = "";
var strMaxHourSuffix = ""
var strMinHourSuffix = ""
var blnChecking = true;
var strError = "";
var i = 0;
var strHour = "";
var strMinute = ""
var strMinMinute = "";
var strMinHour = "";
var strMaxMinute = "";
var strMaxHour = "";
var strCurrentValue = objTbox.value;
if((blnCanBeNull)&&objTbox.value==""

{
return true;
}
if((!blnCanBeNull)&&objTbox.value==""

{
strError = 'Please fill out a correct time in the "' + strControl + '" box.'
blnChecking = false;
}
for(i=0;i<objTbox.value.length;i++){
if((!isNaN(objTbox.value.charAt(i))&&objTbox.value.charAt(i)!=" "

){
strHour = strHour + objTbox.value.charAt(i).toString();
}
if(strHour.length==2){
i++;
break;
}
if(strHour.length>0&&(isNaN(objTbox.value.charAt(i))||objTbox.value.charAt(i)==" "

){
i++;
break;
}
}
while(i<objTbox.value.length){
if((!isNaN(objTbox.value.charAt(i))&&objTbox.value.charAt(i)!=" "

){
strMinute = strMinute + objTbox.value.charAt(i).toString();
}
if(strMinute.length==2){
break;
}
if(strMinute.length>0&&(isNaN(objTbox.value.charAt(i))||objTbox.value.charAt(i)==" "

){
break;
}
i++;
}
if(strHour.length==0||strMinute.length==0){
strError = 'Please fill out a correct time in the "' + strControl + '" box.'
blnChecking = false;
}
if(strHour.length==1&&blnChecking){
strHour = "0" + strHour;
}
if(strMinute.length==1&&blnChecking){
strMinute = "0" + strMinute;
}
if(strTimeFormat.toLowerCase()!="pm/am"&&blnChecking){
if(parseInt(strHour,10)>23||parseInt(strHour,10)<0){
strError = 'Please fill out a correct time in the "' + strControl + '" box.'
blnChecking = false;
}
}else if(blnChecking){
if(parseInt(strHour,10)>12||parseInt(strHour,10)<1){
strError = 'Please fill out a correct time in the "' + strControl + '" box.\nTime format is PM/AM for example: 12:00 PM'
blnChecking = false;
}
}
if((parseInt(strMinute,10)>59||parseInt(strMinute,10)<0)&&blnChecking){
strError = 'Please fill out a correct time in the "' + strControl + '" box.'
blnChecking = false;
}
if(blnRange&&blnChecking){
if(strTimeFormat.toLowerCase()!="pm/am"

{
str24H = parseInt((strHour.toString() + strMinute.toString()),10);
strMinMinute = strMin.substring(2,4);
strMinHour = strMin.substring(0,2);
strMaxMinute = strMax.substring(2,4);
strMaxHour = strMax.substring(0,2);
}else{
var intTmp = 0;
if(objTbox.value.substring(objTbox.value.length-2,objTbox.value.length).toLowerCase()!="am"

{
intTmp = 12;
}
str24H = parseInt((parseInt(strHour,10)+intTmp).toString() + strMinute.toString(),10);
strMinMinute = strMin.substring(2,4);
if(parseInt(strMin.substring(0,2),10)>12){
strMinHour = parseInt(strMin.substring(0,2),10)-12;
strMinHourSuffix = " PM"
}else{
strMinHour = parseInt(strMin.substring(0,2),10);
strMinHourSuffix = " AM"
}
strMaxMinute = strMax.substring(2,4);
if(parseInt(strMax.substring(0,2),10)>12){
strMaxHour = parseInt(strMax.substring(0,2),10)-12;
strMaxHourSuffix = " PM"
}else{
strMaxHour = parseInt(strMax.substring(0,2),10);
strMaxHourSuffix = " AM"
}
}
if(str24H<strMin||str24H>strMax){
strError = "Please use a time between " + strMinHour + ":" + strMinMinute + " " + strMinHourSuffix + " and " + strMaxHour + ":" + strMaxMinute + strMaxHourSuffix
blnChecking=false
}
}
if(blnChecking){
objTbox.style.color = "green";
document.getElementById(strErrLabel).innerHTML = "";
if(strTimeFormat.toLowerCase()=="pm/am"

{
var intTmp = 0;
if(objTbox.value.substring(objTbox.value.length-2,objTbox.value.length).toLowerCase()!="am"

{
strTimeSuffix=" PM";
}else{
strTimeSuffix=" AM";
}
objTbox.value= strHour + ":" + strMinute + strTimeSuffix;
}else{
objTbox.value= strHour + ":" + strMinute
}
}else{
objTbox.style.color = "red";
document.getElementById(strErrLabel).innerHTML = "<font color=red>" + strError + "</font>";
}
return blnChecking;
}
</script>
test text box: 24h<input type=text maxlength=5 id=txttext name=txttext><br>
<input type=button value='test script' onclick="isTime(eval('txttext'),true,'test text box: 24h','lblValidate',true,'0700','2200','24h')" id=button1 name=button1><br>
test text box: PM/AM<input type=text maxlength=8 id=txtpmtext name=txtpmtext><br>
<input type=button value='test script' onclick="isTime(eval('txtpmtext'),false,'test text box: PM/AM','lblValidate',true,'0700','2200','pm/am')" id=button1 name=button1><br>
<br>
<LABEL id=lblValidate></LABEL>