Click here to Skip to main content
14,428,153 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 2

try:
<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>
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Add the following javascript to the HEAD area of your page:
    <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:TextBox ID="TextBox1" runat="server" onkeypress="return isNumberKey(event)"></asp:TextBox>
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Apply this
<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>
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

Hi murali,
Go through the following code and you can use the numeric textbox any of your projects.
Creating Numeric TextBox[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100