/// <summary> ///is a date type string/// </summary> /// <param name= "strsource" >Date String (2008-05-08)</param> /// <returns></returns> Public Static BOOLIsDate (stringstrsource) { returnRegex.IsMatch (strsource,@"^ (((( 1[6-9]|[ 2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d] \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-9]) | (((1[6-9]| [2-9]\d] (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) (xx)) -0?2-29- )) $"); } /// <summary> ///Is a time-type string/// </summary> /// <param name= "source" >time String (15:00:00)</param> /// <returns></returns> Public Static BOOLIstime (stringstrsource) { returnRegex.IsMatch (strsource,@"^ ((20|21|22|23|[ 0-1]?\d): [0-5]?\d:[0-5]?\d) $"); } /// <summary> ///is a date + Time type string/// </summary> /// <param name= "source" ></param> /// <returns></returns> Public Static BOOLIsdatetime (stringstrsource) { returnRegex.IsMatch (strsource,@"^ (((((((( 1[6-9]|[ 2-9]\d) \d{2})-(0?[ 13578]|1[02])-(0?[ 1-9]| [12]\d|3[01]) | (((1[6-9]| [2-9]\d) \d{2})-(0?[ 13456789]|1[012])-(0?[ 1-9]| [12]\d|30)] | (((1[6-9]| [2-9]\d] \d{2}) -0?2-(0?[ 1-9]|1\D|2[0-8]) | (((1[6-9]| [2-9]\d] (0[48]|[ 2468][048]| [13579] [26]) | ((16| [2468] [048]| [3579] [26]) 00)) ( -0?2-29-)) (20|21|22|23|[ 0-1]?\d): [0-5]?\d:[0-5]?\d) $"); } //whether it is an integer Public Static BOOLIsint (stringstrsource) { returnRegex.IsMatch (strsource,@"^[0-9]*$"); }
Determine if the date format is correct