Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was created consultant registration page using ASP.Net], When we enter any characters in text box that will not accept.. Text Box which accepts only numbers!(numeric values only)!!
Posted

 
Share this answer
 
try:
XML
<BODY>
<script language="JavaScript">
function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;

}
</script>
<input type="text" onkeypress="return onlyNumbers();">
</BODY>
 
Share this answer
 
Add the following javascript to the HEAD area of your page:
Java
    <SCRIPT language=Javascript>
   <!--
        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

            return true;
        }
   //-->
</SCRIPT>
Then, add onkeypress to your textbox definition:
ASP.NET
<asp:TextBox ID="TextBox1" runat="server" onkeypress="return isNumberKey(event)"></asp:TextBox>
 
Share this answer
 
Apply this
XML
<asp:TextBox ID="txtNo" runat="server" Style="width: 245px;"></asp:TextBox>
<asp:RegularExpressionValidator Display="Dynamic" ID="RegNo" runat="server" ControlToValidate=" txtNo " ErrorMessage="Please enter a valid number"ValidationExpression="^[0-9 \+\-]*$" ValidationGroup="ValidAll" ForeColor="#DB3100"></asp:RegularExpressionValidator>
 
Share this answer
 
Hi murali,
Go through the following code and you can use the numeric textbox any of your projects.
Creating Numeric TextBox[^]
 
Share this answer
 

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