views:

139

answers:

1

I'm trying to write a custom ASP.NET field validator which makes sure the input is a valid date on the format "yyMMdd".

How do I do that?

+3  A: 

You can try DateTime.ParseExact("091223", "yyMMdd", CultureInfo.InvariantCulture);

EDIT Woops, sorry, didn't see the ASP.NET bit. AFAIK you can make custom validators in ASP.NET? This could be the base of it, and there is also a "TryParseExact" version of the DateTime call, which would allow you to check without exception.

flq
In all cases, for validation code (i.e. invalid format expected) the Try* methods are a better choice.
Richard