Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp:RangeValidator not working

Posted on 2011-02-28
3
Medium Priority
?
1,234 Views
Last Modified: 2012-05-11
I'm having trouble with the following asp:RangeValidator control that if I enter a number where the first two or three digits are in between the range it ignores the last digits and still validates.

the range is 1801 - 2201 but all of these numbers still validate:
19, 20, 21, 212, 202, 190, etc.

The test page is here: http://www.glowfishtw.com/stlukes/alumni.aspx
and the code:

<asp:TextBox ID="txtClass" Width="80px" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClass" MaximumValue="2201" MinimumValue="1801" SetFocusOnError="True"></asp:RangeValidator>

How do I get it to only validate numbers between 1801 and 2201?

Thanks
0
Comment
Question by:elliottbenzle
3 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 2000 total points
ID: 35003893
Your problem probably is because the Maximum and Minimum values are STRINGS (by default) ("2201" and "1801")  and not Numbers.

make this change:

<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Enter a valid year." ControlToValidate="txtClass" MaximumValue="2201" MinimumValue="1801" SetFocusOnError="True" Type="Integer" ></asp:RangeValidator>

AW
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 35004585
As @Arthur_Wood mentioned, you need to add Type="Integer". Also, add a RequiredFieldValidator also, otherwise the blank values will be accepted.
0
 
LVL 4

Author Closing Comment

by:elliottbenzle
ID: 35017910
Thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question