Solved

asp:RangeValidator not working

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bound data table problem 2 34
Finding Events logs for IIS website that restarts 2 14
Need syntax help building hyperlink 2 27
Get month and date in a format 4 35
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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