Date validation

S

Samuel Shulman

Hi

What is the simplest way to validate date input (best if I can use the
ASP.NET validation control)

Thank you,
Samuel
 
M

Mark Rae

What is the simplest way to validate date input (best if I can use the
ASP.NET validation control)

I have my own JavaScript routines for this - what sort of validation are you
looking for...?
 
A

Arundhati Anavekar

use the CompareValidator and set the 'Type' property to 'date'

example:

<asp:CompareValidator id="cvDate" runat="server"
ErrorMessage="Invalid Date inserted" ControlToValidate="Control1"
Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
<asp:Button id="Button1" runat="server" Text="Test it"></asp:Button>


thanks,
aru
 
K

Kevin Spencer

If you want to validate using a regular expression, this will work for
virtually all SQL Server date formats:

(?m)(?i)(?<DateValue>(?:\d{1,4}[-\.-/]\d{1,2}[-\.-/]\d{1,4}|\d{1,2}\s{1,}\w{3,}\s{1,}\d{2,4}|\w{3,}\s{1,}\d{1,2}\s{1,}\d{2,4})(?:\s{1,}\d{1,2}:*\d{1,2}:*\d{1,2}(?:\.*\d*)?\s*(?:A\.?M|P\.?M\.?)?)?)

This includes such format variations as:

2/1/2007
02/01/07
feb 1 2007
1 Feb 2007
2007-02-01
2/1/2007 6:00 PM
2.1.2007
02/01/07 6:00 P.M.
feb 1 2007 18.00.00
1 Feb 2007 18:00:00.666
2007-02-01 06:00:00 PM
2.1.2007 18:00

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.
 
S

Samuel

Thank you all

Kevin Spencer said:
If you want to validate using a regular expression, this will work for
virtually all SQL Server date formats:

(?m)(?i)(?<DateValue>(?:\d{1,4}[-\.-/]\d{1,2}[-\.-/]\d{1,4}|\d{1,2}\s{1,}\w{3,}\s{1,}\d{2,4}|\w{3,}\s{1,}\d{1,2}\s{1,}\d{2,4})(?:\s{1,}\d{1,2}:*\d{1,2}:*\d{1,2}(?:\.*\d*)?\s*(?:A\.?M|P\.?M\.?)?)?)

This includes such format variations as:

2/1/2007
02/01/07
feb 1 2007
1 Feb 2007
2007-02-01
2/1/2007 6:00 PM
2.1.2007
02/01/07 6:00 P.M.
feb 1 2007 18.00.00
1 Feb 2007 18:00:00.666
2007-02-01 06:00:00 PM
2.1.2007 18:00

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

Samuel Shulman said:
Hi

What is the simplest way to validate date input (best if I can use the
ASP.NET validation control)

Thank you,
Samuel
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top