public Boolean TimeIsValid(string time) { DateTime dtTime; if (DateTime.TryParseExact(time, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtTime)) { return(true); } else { var ex = new DateException("Date format is wrong, please try again"); throw ex; } }
public Boolean DateIsValid(string dateString) { DateTime dtDate; if (DateTime.TryParseExact(dateString, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtDate)) { return(true); } else { var ex = new DateException("Date format is wrong, please try again"); throw ex; } }