RangeValidator example in Asp.Net

In this post, we will see an example of how to use RangeValidator in Asp.Net.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

There are different types of validation controls are provided by Asp.Net.

You can also check my previous post on RequiredFieldValidator example in Asp.Net.

– RangeValidator: Here validation succeeds if the input control contains a value within a specific numeric, alphabetic, or date range.

– To use RangeValidator, drag and drop a RangeValidator from Toolbox.

Below are the property need to set:
ControlToValidate: This property field needs to be set as on which field you want to validate.

ErrorMessage: This property will show whatever error message you will give.

MaximumValue: Indicates what will be the maximum value allowed.

MinimumValue: Indicates what will be the minimum value allowed.

Type: Indicates what will be the type. The value can be Integer, Currency, Date, Double or String.

Below is the full HTML code

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”ValidatorExamples.aspx.cs”
Inherits=”ValidatorExamples” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title>RangeValidator example in Asp.Net</title>
<form id=”form1″ runat=”server”>
Enter Age:<asp:TextBox ID=”txtAge” runat=”server”></asp:TextBox>
<br />
<asp:RangeValidator ID=”RangeValidator1″ runat=”server” ErrorMessage=”Age should be between 10 to 90!”
ForeColor=”Red” ControlToValidate=”txtAge” MaximumValue=”90″ MinimumValue=”10″
<br />
<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” />

If you try to submit enter any value in the Textbox which is not between the menimun value and maximum value set then you will get the error message as shown in the figure below:

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →