ASP.NET Check value between given minimum and maximum value using RangeValidator

The RangeValidator is used to check whether or not the value of input control is inside a specified range of value. The RangeValidator control belongs to System.Web.UI.WebControls

Syntax

<asp:RangeValidator ID="RangeValidator2" runat="server" 
ControlToValidate="TextBox2" 
ErrorMessage="Invalid DOB. It must be between 1/1/1990 to 8/2/2015." 
MaximumValue="8/2/2015" MinimumValue="1/1/1990" Type="Date"></asp:RangeValidator>

ASP.NET RangeValidator Control Property

PropertyDescription
ControlToValidateSpecifies control name which needs to be validate.
DisplaySpecifies behavior of the error message.
EnableClientScriptSpecifies whether or not client-side validation is enabled.
EnabledSpecifies whether or not validation control is enabled or not.
ErrorMessageSpecifies error messageto be display in validation summary.
ForeColorSpecifies error message color.
IsValidIndicate if associate control passes validation or not.
SetFocusOnErrorSet focus on associate control if validation fails.
TextSpecifies text to be display if validation fails.
ValidationGroupSpecifies validation group name.
ValidateUpdate the isvalid propery.
ValidateGetValidationPropertyDetermineing validation property of a control, if it exists.
TypeSet data type of input control value.
MinimumValueHolds minimum value of the valid range.
MaximumValueHolds maximum value of the valid range.

Example RangeValidator - Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 
Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ASP.NET RangeValidator Control Example</title>
</head>
<body>
<form id="Form" runat="server">      
<div>
<asp:Label ID="Label1" runat="server" Text="ASP.NET Range Validator Control Example" 
Font-Bold="True" Font-Size="Medium" Font-Underline="True"></asp:Label>
<br /><br />
<table border="0" width="600px" cellpadding="5" cellspacing="0">
<tr><td>
<asp:Label ID="lblAge" runat="server" Font-Bold="True" Font-Size="Small" 
Text="Your Age:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="172px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" 
ControlToValidate="TextBox1" 
ErrorMessage="Invalid Age. Please enter the age between 18 to 30." 
MaximumValue="30" MinimumValue="18" Type="Integer"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
ControlToValidate="TextBox1" ErrorMessage="This is required field, can not be blank."></asp:RequiredFieldValidator>
</td></tr>
<tr><td>
<asp:Label ID="lblDOB" runat="server" Font-Bold="True" Font-Size="Small" 
Text="Date of Birth (mm/dd/yyyy) :"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="172px"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator2" runat="server" 
ControlToValidate="TextBox2" 
ErrorMessage="Invalid DOB. It must be between 1/1/1990 to 8/2/2015." 
MaximumValue="8/2/2015" MinimumValue="1/1/1990" Type="Date"></asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
ControlToValidate="TextBox2" ErrorMessage="This is required field, can not be blank."></asp:RequiredFieldValidator>
</td></tr>
<tr><td>
<asp:Button ID="tblSubmit" runat="server" Font-Bold="True" 
Font-Size="Small" Text="Submit" />
</td></tr>
</table>
</div>
</form>
</body>
</html>

Above example will produce following output

More ASP.NET RangeValidator Controls

 
SHARE THIS IF YOU LIKE!
submit to reddit

SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.