ASP.NET: Validate text box contains integer greater than equal to zero?

19.1k Views Asked by At

If I want to validate that a text box contains an integer greater than or equal to zero. Do I need to use TWO asp:CompareValidator controls: one with a DataTypeCheck operator and one with a GreaterThanEqual operator?

Or is the datatype operator redundant? Can I just use a single validator with the GreaterThanEqual operator (and the type set to Integer)?

1

There are 1 best solutions below

4
On BEST ANSWER

This should be enough

<asp:RangeValidator id="Range1"
           ControlToValidate="TextBox1"
           MinimumValue="0"
           MaximumValue="2147483647"
           Type="Integer"
           Text="The value must be integer and greater or equal than 0"
           runat="server"/>