Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Textbox to accept numbers only using javascript in asp.net

How to allow only integers in a textbox or Allow only numeric value ( numbers ) in TextBox using JavaScript or Allow only numeric values to be entered in a textbox using JavaScript in Asp.net

<head>
 <script language="javascript" type="text/javascript">  
        function CheckNumeric(e) {

            if (window.event) // IE
            {
                if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8) {
                    event.returnValue = false;
                    return false;

                }
            }
            else { // Fire Fox
                if ((e.which < 48 || e.which > 57) & e.which != 8) {
                    e.preventDefault();
                    return false;

                }
            }
        }
    </script>
</head>
<body><table>
  <tr>
                                    <td>
                                        <strong>Mobile No</strong>
                                    </td>
                                 
                                    <td>
                                        <asp:TextBox ID="txtMobile" runat="server" Height="23px" Width="246px"
                                          onkeypress="CheckNumeric(event);"  MaxLength="11"></asp:TextBox>
                                    </td>
                                </tr>
</table>
</body>


This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Textbox to accept numbers only using javascript in asp.net

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×