From the set of validation server controlin asp.net we will see how to use RangeValidator in this post.
RangeValidator is used to check if values entered are in between specific range or not. In order to use RangeValidator, we need to add server control
RangeValidator example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter a number between 0 and 5:
<br>
<asp:TextBox ID="txtNumber" runat="server" />
<asp:RangeValidator ID="RangeValidator1" ControlToValidate="txtNumber" MinimumValue="0"
MaximumValue="5" Type="Integer" Text="The number should be in between 0 to 5."
ForeColor="red" runat="server" />
<br>
<asp:Button ID="Button1" Text="Submit" runat="server" />
</div>
</form>
</body>
</html>
In order to rangevalidator to be work we need to set few properties:
1. Minimum value
2. Maximum value
3. Control to validate
4. Type of data i.e. Interger, Date...etc.
5. And the Text for error message