There are regexes out there which will do this, (mahen25 has linked to site giving at least one) but the problem is that they are very complex, and not very maintainable.
You might be better off just using
DateTime.TryParseExact[
^] and using the result that way.
DateTime date;
String myDate = "30/11/2011";
if (DateTime.TryParseExact(myDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
Console.WriteLine("OK");
}
else
{
Console.WriteLine("Error");
}
String myWrongDate = "31/11/2011";
if (DateTime.TryParseExact(myWrongDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
Console.WriteLine("OK");
}
else
{
Console.WriteLine("Error");
}