Tuesday, March 3, 2009

Use Compare Validator to check your Integers!

Here's an easy way to check to make sure that the User enters an Integer in an Integer field.
<asp:CompareValidator ID="CompareValidatorErrors" ErrorMessage="Please Enter an Integer" Type="Integer" Operator="DataTypeCheck" ControlToValidate="TxtNumberErrors" runat="server"></asp:CompareValidator>

You can specify the ValidationTypeProperty within the Type property to specify (Currency, DateTime, Double, Integer, String) to Compare against.

1 comment: