How to use RangeValidator Control in ASP.Net ?

In this asp.net article i will explain you how to use RangeValidator control in ASP.Net.

RangeValidator control is used to checks the input control’s value is within a specified range, Means input values must be between two values,  It has minimum and maximum value.

Generally we use RangeValidator control for Mobile no and Pincode Number.

The most important properties of the RangeValidator control are MaximumValue, MinimumValue, and Type.

We must specify the Range from Minimum values to Maximum Values and Type of Input Values.

MaximumValue – Specify the MaximumValue of Input Value
MinimumValue -Specity the MinimumValue of Input Value
Type - Specify the Data Type of Input Value

Now, we will learn how to use rangevalidator in asp.net with an example.

First design asp.net web form as follow:

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

Here is the HTML design code for above web form.

Now,  Drag and drop RangeValidator control on web forms like below.

rangevalidator in asp.net

How to use RangeValidator control in asp.net

Here, we validate the TextBox for Mobile Number. Mobile no must be 10 digit.

First set ControlToValidate property = textbox mobile  as below.
and set ErrorMessage = “Invalid Mobile !!”

Now , set the Minimum and Maximum value property of range validator control for mobile number.

For Mobile Number :

MinimumValue = 1111111111
MaximumValue = 9999999999
Type = Double

Below screen shows the if we entered 9 digit in mobile textbox then validator control shows the error message.

same thing for Pincode Number, Pincode number must be 6 digit.

For Pincode Number :

MinimumValue = 111111
MaximunValue = 999999

 

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

 

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

Now, we take another example for type string values.

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

Here set the RangeValidator control Property for String

MaximunValue = K
MinimumValue = D
Type = String

 

Here, the textbox allow only character between D and K.
Below screen we entered E, so it doesn’t shows the error message.

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

Here, we have entered B, then B is not between D and K so it will shows the ErrorMessage.

How to use RangeValidator control in asp.net

How to use RangeValidator control in asp.net

I hope this asp.net RangeValidator control example will help you…..

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 2 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">