Click here to Skip to main content
15,886,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a regulare expression to validate my date with time in this format
dd-MMM-yyyy HH:mm

and the regulare expression i use is
C#
"^(0?[1-9]|[12][0-9]|3[01])-(jan|Jan|JAN|feb|Feb|FEB|mar|Mar|MAR|apr|Apr|APR|may|May|MAY|jun|Jun|JUN|jul|Jul|JUL|aug|Aug|AUG|sep|Sep|SEP|oct|Oct|OCT|nov|Nov|NOV|dec|Dec|DEC)-(19|20)\d\d\s([0-1][0-9]|[2][0-3]):([0-5][0-9])$"


it will validate date like this...

C#
12-oct-2010 20:21  //Valid
22-Nov-1988 03:52  //Valid
02-DEC-2022 23:59  //Valid


but my question is that i want also alow user to enter a blank value for entire block with dd-MMM-yyyy HH:mm and also want to validate the day contains by the coreosponding month..

i want the resulted out put like this...

C#
__-___-____ __:__  /*Valid because i have allowed blank value to enter by user*/
31-Nov-2011 12:23 /* Not Valid because November has only 30 Days */
31-JUN-2011 13:09 /*Not Valid because June has only 30 Days...*/
Posted
Updated 15-Nov-11 23:04pm
v2

1 solution

Why even bother with the validation. Don't allow a date/time to be entered as text, use a calendar control. Or use DateTime.TryParse to validate
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Nov-11 5:27am    
Exactly. My 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900