Wednesday, November 2, 2016

javascript to allow only number

Call javascript function as shown below in content or header section:-

 <script type="text/javascript">

  function isNumberKey(evt, element) {
          
            var charCode = (evt.which) ? evt.which : event.keyCode;
            if (charCode == 46 && evt.srcElement.value.split('.').length > 1) {
                return false;
            }
            if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;


        }
 </script>

Call javascript function from inside the Textbox :-

 <asp:TextBox ID="textbox1" Width="85px" runat="server" MaxLength="25" TabIndex="3"
                                   onkeypress="return isNumberKey(event,this)"></asp:TextBox>

No comments:

Post a Comment