Conditions for minutes  :
         1. one digit or two digits can exists.
         2. it must be less than or equal to 60 and greater than 0
             Here it is regular expression ::
                                /^([0][0-9]|[0-5][0-9]|[0-9]|[6][0])$/

Here it is java script function :

    function validateMinutes(id) {
      var val=document.getElementById(id).value;
      var reg = /^([0][0-9]|[0-5][0-9]|[0-9]|[6][0])$/;
      alert(reg.test(val));
   }


Undo Input Value if its not minutes :

function validateMinutes(id) {
 var val=document.getElementById(id).value;
 var reg = /^([0][0-9]|[0-5][0-9]|[0-9]|[6][0])$/;
 if (reg.test(val)){
 }
 else {
   var len=val.length;
   document.getElementById(id).value=val.substring(0,len-1);
 }
}

Html Code :

<input id="input1" name="input1" onkeyup="return validateMinutes('input1');" size="2" maxlength="2" value="00"/>

0 comments:

Blogroll

Follow this blog by Email

Popular Posts