Click here to Skip to main content
16,020,459 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to validate date in format MM/DD/YYYY exactly in the same format.
Please help
And is it possible to extract range of date with regex?
Posted

Don't use a regex: you can do it, but it's horribly complex when you start thinking about 28 day months, 30 day, and 31 day months, and then there are leap years...
Try:
DateTime dt;
if (DateTime.TryParseExact("04/17/2015", "MM/dd/yyyy", CultureInfo("en-US"), DateTimeStyles.None, out dt))
   {
   ...
 
Share this answer
 
Try "(((0|1)[1-9]|2[1-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$" as your expression.
 
Share this answer
 
Hi,

C#
DateTime Test;
       if ((!string.IsNullOrEmpty(strtdate)))
       {
           bool valid = DateTime.TryParseExact(strtdate, "M/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out Test);
       }


Ref : Validate the string entered is of mm/dd/yyyy format
 
Share this answer
 

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