How to validate a TextBox to accept only Integer value only (or any specific data types)

Posted by Raja under ASP.NET category on | Views : 13472
We can use CompareValidator along with Operator and Type parameter.

<asp:TextBox ID="txtInt" runat="server" ></asp:TextBox>
<asp:CompareValidator ID="Comp1" runat="server" ErrorMessage="Please write interger only"
ControlToValidate="txtInt" Operator="DataTypeCheck" Type="Integer" ></asp:CompareValidator>

In the same way, the
Type property can be specified as Currency, Date, Double, String.
Operator can be specified as Equal, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual and NotEqual.

Comments or Responses

Login to post response