Search code examples
asp.nettextboxvalidationcomparevalidator

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


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


Solution

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