In .NET, to determine whether a supplied string is a date, which one is quicker: using DateTime to cast it to a date, or using a regular expression to check the string for its validity as a date?
I just need to ensure the value supplied is a date, and I’m not doing anything with it afterward.
Thanks.
A good regex should be much faster, and maybe consume less transient memory.
But here’s the flipside of the coin:
You’re pretty-much tied to only one time format, which means that internationalization will be painful, and that your users need to be educated to enter the date in the proper format.
Also, you will lose some date validation, say, how do you weed-out Feb 29th on non leap-years? April 31st?