Range validator for date

T

tshad

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
 
D

dan.c.roth

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
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"
 
Joined
Aug 16, 2011
Messages
1
Reaction score
0
Validate Date using Range Validator

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top