Solved

asp:RangeValidator not working

Posted on 2011-02-28
3
1,198 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 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now