Reputation: 109
I am working on creating a regular expression to verify a date in multiple formats and I have found plenty of info on how to handle a date in the following formats:
06/19/2013
06-19-2013
06 19 2013
06.19.2013
but I cannot seem to get the regex to handle
06192013
Here is my regular expression:
((0?[1-9]|1[012])[- \/.](0?[1-9]|[12][0-9]|3[01])[- \/.]((19|20)?[0-9]{2}
How do I handle the date with no delimiters?
Upvotes: 3
Views: 1216
Reputation: 664385
Just make it optional:
(0?[1-9]|1[012])[- \/.]?(0?[1-9]|[12][0-9]|3[01])[- \/.]?(19|20)?[0-9]{2}
^ ^
Upvotes: 3
Reputation: 4408
Why don't you use DateTime.TryParseExact()
?
http://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact.aspx
Upvotes: 0