Please see my question. I hope you can decide to work without non-standard things like "14th".
You don't really need to use Regular Expressions. It will be way more reliable method to parse string as a date or time structure. In case of success, it's valid; if parsing fails, it is not. Very simple.
On client side, it will be JavaScript like this:
function IsValidDate(dateString) {
return !isNaN(Date.parse(dateString));
}
On server side, you need to do the same thing using
System.DateTime
methods
Parse
or
ParseExact
. Unlike JavaScript, you will need to supply input string in exact format corresponding to required culture information (
IFormatProvider
) and/or format specifiers; but for
Parse
method, there are variants: date only, time only, both, and the culture should correspond current thread culture.
Besides, you need to call such method in the try-catch block as it can catch exception. For example:
static bool IsValidDate(string value) {
try {
System.DateTime.Parse(value);
return true;
} catch(System.FormatException) {
return false;
}
}
Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[
^].
For time string formats, please see:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[
^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[
^].
—SA