Posted by : Anwar Hossain
Category : How to use different types of validation control using asp.net c#

How to use RangeValidator in ASP.NET C#

Dear Viewers I will show how to use how to use RangeValidator control in ASP.NET C#. Sometimes we need to define what range of data will be input by the users that means minimum and maximum value. In this case RangeValidator is best for an ASP.NET developer. It has different type data type to check such as currency, date, double, integer, and string. So I have used various type data type to validate ASP.Net textbox control using RangeValidator Control.

RangeValidator in ASP.NET C#

HTML

<html xmlns ="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <style type="text/css">
  .style1
  {
  width: 100%;
  }
  .style2
  {
  color: #0099FF;
  font-weight: bold;
  }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <table class="style1">
  <tr>
  <td align="right">
  <span class="style2">Range Validator for Integer</span>
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtRange" runat="server" Width="250px"></asp:TextBox>
   <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtRange"
  ErrorMessage="Enter age value betwen 10 to 80" ForeColor="#FF3300" MaximumValue="80"
  MinimumValue="10" Type="Integer"></asp:RangeValidator>
  </td>
  </tr>
  <tr>
  <td align="right">
  <span class="style2">Range Validator for Double</span>
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtdecemal" runat="server" Width="250px"></asp:TextBox>
  <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtdecemal"
  ErrorMessage="Enter Minimum  0 to 99.90" ForeColor="#FF3300" MaximumValue="99.99"
  MinimumValue="0" Type="Currency"></asp:RangeValidator>
  </td>
  </tr>
  <tr>
   <td align="right">
  <span class="style2">Range Validator for Currency</span>
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtCurrency" runat="server" Width="250px"></asp:TextBox>
  <asp:RangeValidator ID="RangeValidator3" runat="server" ControlToValidate="txtCurrency"
  ErrorMessage="Enter Minimum  0 to 99.90" ForeColor="#FF3300" MaximumValue="99.99"
  MinimumValue="0" Type="Double"></asp:RangeValidator>
  </td>
  </tr>
  <tr>
  <td align="right">
  <span class="style2">Range Validator for Date type</span>
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtDate" runat="server" Width="250px"></asp:TextBox>
   <asp:RangeValidator ID="RangeValidator4" runat="server" ControlToValidate="txtDate"
  MaximumValue="12/31/2014" MinimumValue="12/12/2005" Type="Date" ErrorMessage="The date must be between 12/12/2005 and 12/31/2014"
  ForeColor="#FF3300"></asp:RangeValidator>
  </td>
  </tr>
  <tr>
  <td align="right">
  <span class="style2">Range Validator for Integer</span>
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtZip" runat="server" size="5" Width="250px" />
  <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtZip"
  ValidationExpression="[0-9]{5}" ErrorMessage="Insert Valied Zip" ForeColor="#FF3300" />
  <asp:RangeValidator ID="RangeValidator5" runat="server" ControlToValidate="txtZip"
  MinimumValue="00000" MaximumValue="44444" Type="String" ErrorMessage="Insert Correct Area"
  ForeColor="#FF3300" />
  </td>
  </tr>
  <tr>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  </tr>
  <tr>
   <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  </tr>
  </table>
  </div>
  </form>
</body>
</html>

Out Put

 RangeValidator in ASP.NET C#



Realted Article Headline

How to use RequiredFieldValidator for RadioButtonList in ASP.NET C#
How to use RequiredFieldValidator for DropDownList in ASP.NET C#
How to use RangeValidator in ASP.NET C#
how to use RequiredFieldValidator in ASP.NET C#
How to use RegularExpressionValidator Control in ASP.NET using C#
How to use Custom Validator control using asp.net c#
How to use compare validation control using asp.net c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection