I am using MaskedEditExtender for entering a datetime. I am unable to figure out how to validate it.
Is there any Regular Expression for validating dates along with
Use DateTime.Parse or DateTime.TryParse (there are also ParseExact and TryParseExact equivalents).
If the string does not represent a valid DateTime
it will not parse.
DateTime myDateTime = DateTime.ParseExact(myString,
"MM/dd/yyyy hh:mm",
CultureInfo.InvariantCulture);
The above will throw an exception if the value is not parseable. Use the Try
variant if you want to avoid the chance of the exception being thrown - this requires an out
parameter and testing the return value of the function for success.