Range validator - DotNet and DataBase

Follow us on Facebook

SQL Server Mountain View Mountain View Mountain View

Saturday, 18 August 2018

Range validator

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>

<%@ 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">
    <form id="form1" runat="server">
                      UserName:  <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="UserName is required." ControlToValidate="txtUserName"></asp:RequiredFieldValidator></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>
                        <asp:Button ID="btnSubmit" runat="server" Text="Submit"  /></td>


Here MinimumValue and MaximumValue are the validation conditions which restrict the age within 18-35. 


No comments:

Post a comment


Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.