Skip to content

Instantly share code, notes, and snippets.

@prakash-patel
Created November 25, 2014 15:15
Show Gist options
  • Save prakash-patel/b11b8547c99afd8f87df to your computer and use it in GitHub Desktop.
Save prakash-patel/b11b8547c99afd8f87df to your computer and use it in GitHub Desktop.
Validate the date time
/// <summary>
/// Validates the date time. yyyymmddhhmmssfffk
/// </summary>
/// <param name="dateString">The date string.</param>
public bool ValidateDateTime(string dateString)
{
const string malformedTimeZone =
@"^\d{4}(?:(?:0[0-9]|1[0-2])(?:(?:[0-2][0-9]|3[0-1]))?(?:(?:[0-1][0-9]|2[0-4]))?(?:(?:[0-5][0-9]))?(?:(?:[0-5][0-9])(?:\.\d+)?)?)?(?:[+-](0[0-9]|1[0-2]):[0-5][0-9])?$";
return Regex.IsMatch(dateString, malformedTimeZone);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment