Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ValidationExpresion for Date format MM/DD/YYYY

Status
Not open for further replies.

ravula2000

IS-IT--Management
Mar 8, 2002
205
US
What is the ValidationExpresion to validate for the date format “MM/DD/YYYY” (It should take care of Leap year also) to assign to the RegularExpressionvalidator
Please help

Thanks
Srinivas
 
You can set the following as the value for the ValidationExpression property of a RegularExpressionValidator:

^([0-9]{1,2})[./-]+([0-9]{1,2})[./-]+([0-9]{2}|[0-9]{4})$

This allows either MM/DD/YYYY or MM-DD-YYYY
 
The problem with this regular expression though is it only matches the pattern of digits and seperators and doesnt check wether the date is valid or not. An expression which allowed for all the possible combinations of days in months as well as leap years is horrific to even contemplate.

A better way to approach this would be to use a custom validator and have a method which validates the date as well as the pattern. This also allows you to add extra checks such as acceptable date ranges.

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Good site jasonsalas - cheers!

And they do have a regex for validating date as well as pattern but it is a real monster.....

Rob

------------------------------------

On with the dance! let joy be unconfined;
No sleep till morn, when Youth and Pleasure meet
To chase the glowing hours with flying feet.
-Byron

------------------------------------
 
Yeah...there's lots of good code there...a good friend of mine put the site together and if the chief contributor. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top