Range validator is to identify whether the user-supplied data within the specified range or not. For example, User registration form is having a User age control, it should accept users who are in the age between 18 to 35. Using Range validator we can restrict the users who are between 18-35.
><asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Error message" ControlToValidate="control to validate" MinimumValue="minimum value" MaximumValue="maximum value"></asp:RangeValidator>
Example:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RequiredFieldvalidator.aspx.cs" Inherits="WebProgramming.Validators.RequiredFieldvalidator" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
UserName: <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="UserName is required." ControlToValidate="txtUserName"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>
Age: <asp:TextBox ID="txtAge" runat="server"></asp:TextBox><asp:RangeValidator ID="rfvAge" runat="server" ErrorMessage="User age should be with in 18-35." ControlToValidate="txtAge" MinimumValue="18" MaximumValue="35"></asp:RangeValidator></td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Here MinimumValue and MaximumValue are the validation conditions which restrict the age within 18-35.
Output




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
No comments:
Post a Comment