Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Range validator for date

Reply
Thread Tools

Range validator for date

 
 
tshad
Guest
Posts: n/a
 
      05-23-2005
I have been trying to set up a range validator and regular expression for my
dates.

I tried this:

<asp:RangeValidator runat="server"
ControlToValidate="AbsentFrom1"
MinimumValue="12/31/1950"
MaximumValue="1/1/2100"
Type="Date" text="Invalid Date"/>

Which doesn't seem to work at all.

I put in 1/15/1940 and it didn't give me an error.

I need this because my regular expression won't handle leap years and I
don't want to have to deal with different type of years over and about 2 or
4 characters. My RegularExpressionValidator (which does work) is:

<asp:RegularExpressionValidator ControlToValidate="AbsentFrom1"
ValidationExpression="^(([1-9])|(0[1-9])|(1[0-2]))\/(([1-9])|(0[1-9])|(1[0-9
])|(2[0-9])|(3[0-1]))\/((\d{2})|(\d{4}))$" Display="Dynamic" Text="<br>From
Date Invalid or in wrong Format(MM/DD/YY)" runat="server"/>

Why doesn't the range validator work?

Is there a better way to validate my dates?

Thanks,

Tom



 
Reply With Quote
 
 
 
 
dan.c.roth@gmail.com
Guest
Posts: n/a
 
      05-23-2005
Hi

Use CompareValidator for that date type and RangeValidator for the
range like so:

<asp:CompareValidator id="CompareValidator1" runat="server"
ErrorMessage="CompareValidator" Type="Date"
ControlToValidate="TextBox1"
Operator="DataTypeCheck"></asp:CompareValidator>
<asp:RangeValidator id="RangeValidator1" runat="server"
ErrorMessage="RangeValidator" MaximumValue="2010-01-01"
MinimumValue="2009-01-01"
ControlToValidate="TextBox1">RangeValidator</asp:RangeValidator>
<asp:TextBox id="TextBox1" runat="server">2010-01-01</asp:TextBox>

Regards,

Daniel Roth
MCSD.NET

tshad wrote:
> I have been trying to set up a range validator and regular expression

for my
> dates.
>
> I tried this:
>
> <asp:RangeValidator runat="server"
> ControlToValidate="AbsentFrom1"
> MinimumValue="12/31/1950"
> MaximumValue="1/1/2100"
> Type="Date" text="Invalid Date"/>
>
> Which doesn't seem to work at all.
>
> I put in 1/15/1940 and it didn't give me an error.
>
> I need this because my regular expression won't handle leap years and

I
> don't want to have to deal with different type of years over and

about 2 or
> 4 characters. My RegularExpressionValidator (which does work) is:
>
> <asp:RegularExpressionValidator

ControlToValidate="AbsentFrom1"
>

ValidationExpression="^(([1-9])|(0[1-9])|(1[0-2]))\/(([1-9])|(0[1-9])|(1[0-9
> ])|(2[0-9])|(3[0-1]))\/((\d{2})|(\d{4}))$" Display="Dynamic"

Text="<br>From
> Date Invalid or in wrong Format(MM/DD/YY)" runat="server"/>
>
> Why doesn't the range validator work?
>
> Is there a better way to validate my dates?
>
> Thanks,
>
> Tom


 
Reply With Quote
 
 
 
 
shekharshete_2005 shekharshete_2005 is offline
Junior Member
Join Date: Aug 2011
Posts: 1
 
      08-16-2011
Hi,
I want to validate the Date using Range Validator with min val:01/01/1900 and max value with 01/01/1993 to calculate at least 18yr old for voting!
The date is in MM/DD/YYYY but i get the Error how to do?

Plz help!
Shekhar Shete,INDIA
MCTS
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts Validator - creditCard validator smrimell@gmail.com Java 4 02-13-2007 08:32 PM
Todays date in range validator? Tarun Mistry ASP .Net 2 02-22-2006 09:33 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments