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

User picture User · Mar 29, 2010 · Viewed 18.5k times · Source

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)?

Answer

Claudio Redi picture Claudio Redi · Mar 29, 2010

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"/>