You Tube

Friday 3 February 2017

textbox accept only numbers in javascript ?

<SCRIPT language=Javascript>
          function allow_num(num) {
        var charCode = (num.which) ? num.which : num.keyCode;
        if (charCode != 46 && charCode > 31
            && (charCode < 48 || charCode > 57))
            return false;

        return true;
    }
</SCRIPT>
 
call this function:
 <asp:TextBox ID="txt_num" onkeypress="return allow_num(event)" CssClass="txt" runat="server"></asp:TextBox>
 
 <input id="Text1" onkeypress="return allow_num(event)" type="text" />

No comments:

Post a Comment