0

my question is simple, I need to know how to only allow integers to my InputBox in ASP.Net C#, without that tag thing , is there any other way ?

Thank you guys

3 Answers3

0

The code is :

function numericFilter(txb) {
   txb.value = txb.value.replace(/[^\0-9]/ig, "");
}

call it in on key up

<input type="text" onKeyUp="numericFilter(this);" />
0
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="Only Numbers allowed" ValidationExpression="\d+"></asp:RegularExpressionValidator>
user2960398
  • 363
  • 4
  • 19
0

You can use a asp:CompareValidator. Like this:

<asp:TextBox ID="txtTotal" runat="server"></asp:TextBox>
<asp:CompareValidator ID="compTotal" 
    runat="server"
    ControlToValidate="txtTotal" 
    ErrorMessage="ValueNotNumeric" 
    Type="Integer" Operator="DataTypeCheck"></asp:CompareValidator>
Arion
  • 31,011
  • 10
  • 70
  • 88