Mega Code Archive

 
Categories / JavaScript DHTML / Data Type
 

Validate a time value input with string indexOf method

<HTML> <HEAD> <SCRIPT language="JavaScript"> function check_it() {      var thetext=document.myForm.the_time.value;      if (thetext.indexOf(":") == -1)      {           window.alert("No colon(:)");           return false;      }      else      {          return true;      } } </SCRIPT> </HEAD> <BODY> <FORM name="myForm" action="#" onSubmit="return check_it();"> Time:<INPUT type="text" name="the_time"> <INPUT type="submit" value="Submit"> </BODY> </HTML>