Validation in ASP.NET
page 5 of 9
by . .
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 32954/ 94

Using Ranges


This lets you see if a value is between two ranges. The range (set in MinimumValue and MaximumValue can either be a string or number). This checks to see if a zip code is within a specified range, I also used a Regular Expression Validator to check it too.

Please Enter your Zip Code:<asp:textbox id="ZIP" runat="server" /><p>

<asp:RangeValidator runat="server" ControltoValidate="ZIP" ErrorMessage="Your Zip isn't within the range (8000 - 9000)!" MinimumValue="8000" MaximumValue="9000" />

<asp:RegularExpressionValidator runat="Server" ControltoValidate="ZIP" ErrorMessage="That Zip code is invalid (numbers only and 4 numbers long!)" ValidationExpression="[0-9]{4}|[0-9]{5}" />

The RangeValidator made sure that you kept the value between 8000 and 9000, the regular expression one made sure that it was 4 or 5 (someone would complain if it was only 4) numbers long and only numbers.

View Entire Article

User Comments

Title: Nice   
Name: Nagesh
Date: 2004-07-13 9:49:31 AM
Thanks for such quick review ....
Title: GOOD   
Date: 2004-07-13 8:28:00 AM
But where is the code!!!!!!!!!!!!!!!!!

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2021  |  Page Processed at 2021-03-05 3:16:46 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search