Converting DateTimeFormatInfo.ShortDatePattern to Regex

329 Views Asked by At

I have a validator extending from BaseValidator that is scattered throughout the code. I feed in a regular expression string which is then used for server-side and client-side validation. When used for date fields, this string currently uses the same format across all cultures, but I would like to make use of the short date pattern found in Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern. Is there something built-in for converting a date pattern to a regular expression? Most of the other answers on Stack Overflow say to use DateTime.TryParseExact, but I'd be impressed if that would work for client-side validation.

Yes, we could use some sort of Datetime picker, but the product owner won't approve of that any time soon.

0

There are 0 best solutions below