/**/ /// <summary> /// 是否是数字型 /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsNumeric( string value) ... { return Regex.IsMatch(value, @"^[+-]?d*[.]?d*$"); } /**/ /// <summary> /// 是否是整数 /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsInt( string value) ... { return Regex.IsMatch(value, @"^[+-]?d*$"); } /**/ /// <summary> /// 是否是无符号数字 /// </summary> /// <param name="value"></param> /// <returns></returns> public static bool IsUnsign( string value) ... { return Regex.IsMatch(value, @"^d*[.]?d*$"); } /**/ /// <summary> /// 是否是日期型 /// 支持的格式包括("1980-06-06"和"1980/06/06") /// </summary> /// <param name="dateStr"></param> /// <returns></returns> public static bool IsDate( string dateStr) ... { string datePat =@"^(d{4})(/|-)(d{1,2})(/|-)(d{1,2})$"; bool IsMatch=Regex.IsMatch(dateStr,datePat); //日期格式不正确,正确格式:1980-06-06 if(!IsMatch) return false; string[] dates=dateStr.Split('/','-'); if(dates==null || dates.Length<3) return false; int year =int.Parse(dates[0]); int month =int.Parse(dates[1]); int day =int.Parse(dates[2]); if (month < 1 || month > 12) ...{ //"月份必须是1月-12月之间"; return false; } if (day < 1 || day > 31) ...{ //"日必须是1-31日之间"; return false; } if ((month==4 || month==6 || month==9 || month==11) && day==31) ...{ //month doesn't have 31 days!" return false; } if (month == 2) ...{ // check for february 29th bool isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day > 29 || (day==29 && !isleap)) ...{ // year + " 年 2 月没有 " + day + " 日" return false; } } return true; // date is valid } #endregion 转载于:https://www.cnblogs.com/pbwf/archive/2007/05/26/761100.html