Click here to Skip to main content
16,012,082 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the textbox must contain only numeric values...So i added this function given below

C#
function nummins(evt) {
            var vlr;
            var vlr = (window.event) ? event.keyCode : evt.which;
            if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
                return true;
            }
            else {
                alert("Time should be a Numeric Value");
                return false;
            }
        }


It gives me correct output...
But my problem is in this function I want a code for 12hr time format i.e.,the textbox value must be 1 to 12....

Can anyone help me....
Posted

Before return true, add the following code
Take one more argument to this function to refer current object i.e. textbox
C#
function nummins(evt,this) {
            var vlr;
            var vlr = (window.event) ? event.keyCode : evt.which;
            if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
                 
                var num=Number(this.value);
                if(num>12)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else {
                alert("Time should be a Numeric Value");
                return false;
            }
        }


it might be useful,
 
Share this answer
 
Comments
vivekx2 17-Feb-12 10:40am    
thank uuu...
C#
function nummins(evt,val) {
            var vlr;
            var vlr = (window.event) ? event.keyCode : evt.which;
            if ((vlr >= 48 && vlr <= 57) || vlr == 8) {
       if(val<13)
             {
                return true;
          }
        else
        {
          return false;

         }
            }
            else {
                alert("Time should be a Numeric Value");
                return false;
            }
        }
<input type="text" id="txt" onkeypress="return nummins(evt,this.value)"></input>
 
Share this answer
 
Comments
vivekx2 17-Feb-12 10:40am    
thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900