Introduction:

In this article we will learn how to use RangeValidator in asp.net or what is RangeValidator in asp.net or why use RangeValidator in asp.net with example.

Description:

ASP.NET RangeValidator is used to check whether input value is in given range or not.  it makes sure that the user input is within a specified range. You can use it to validate both numbers, strings and dates.

Let’s see Example:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RangeValidator.aspx.cs"
Inherits="Example.RangeValidator" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Enter Amount:<br />
    <asp:TextBox runat="server" id="txtamount" /><br />
<asp:RangeValidator runat="server" id="rngamount" controltovalidate="txtamount"
Style="color:red;"type="Double" minimumvalue="0" maximumvalue="10000"
errormessage="Please enter a valid amount less than or equal 10000!" />
<br />
<br />
    </div>
    </form>
</body>
</html>

 

In above example if we entered minimum value zero and maximum value 10000 in textbox that’s valid. But we entered greater than 10000 that is invalid and give error message.

 

Output:


How to use RangeValidator in Asp.Net


I hope this article will help to you.


comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like