#region // Fields
private static Regex RegDecimal;
private static Regex RegCHZN;
private static Regex RegDecimalSign;
private static Regex RegEmail;
private static Regex RegNumber;
private static Regex RegNumberSign;
#endregion
#region // Methods
/// <summary>
/// 构造函数
/// </summary>
public CheckData()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
static CheckData()
{
RegNumber = new Regex("^[0-9]+$");
RegNumberSign = new Regex("^[+-]?[0-9]+$");
RegDecimal = new Regex("^[0-9]+[.]?[0-9]*$");
RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]*$");
RegEmail = new Regex(@"^[/w-]+@[/w-]+/.(com|cn|net|org|edu|mil|tv|biz|info)$");
RegCHZN = new Regex("[/u4e00-/u9fa5]");
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息适用于 2006/06/13 格式
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <returns></returns>
public static string CheckDate(string Sour)
{
return CheckDate(Sour, true, true);
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <param name="IsUpToday">是否必须大于今天</param>
/// <param name="IsNotNull">是否不可以为空值</param>
/// <returns></returns>
public static string CheckDate(string Sour, bool IsUpToday, bool IsNotNull)
{
if (IsNotNull)
{
if (Sour == "")
{
return "日期不能为空";
}
}
else if (Sour == "")
{
return "";
}
if (IsUpToday && (Sour.CompareTo(DateTime.Now.ToString(@"yyyy//MM//dd")) < 0))
{
return "日期不能小于当前日期";
}
if (!RegDate(Sour))
{
return "日期格式不正确,应为【2002/09/06】";
}
return "";
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <param name="IsUpToday">是否必须大于今天</param>
/// <returns></returns>
public static string CheckDate(string Sour, bool IsUpToday)
{
return CheckDate(Sour, IsUpToday, true);
}
private static Regex RegDecimal;
private static Regex RegCHZN;
private static Regex RegDecimalSign;
private static Regex RegEmail;
private static Regex RegNumber;
private static Regex RegNumberSign;
#endregion
#region // Methods
/// <summary>
/// 构造函数
/// </summary>
public CheckData()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
static CheckData()
{
RegNumber = new Regex("^[0-9]+$");
RegNumberSign = new Regex("^[+-]?[0-9]+$");
RegDecimal = new Regex("^[0-9]+[.]?[0-9]*$");
RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]*$");
RegEmail = new Regex(@"^[/w-]+@[/w-]+/.(com|cn|net|org|edu|mil|tv|biz|info)$");
RegCHZN = new Regex("[/u4e00-/u9fa5]");
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息适用于 2006/06/13 格式
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <returns></returns>
public static string CheckDate(string Sour)
{
return CheckDate(Sour, true, true);
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <param name="IsUpToday">是否必须大于今天</param>
/// <param name="IsNotNull">是否不可以为空值</param>
/// <returns></returns>
public static string CheckDate(string Sour, bool IsUpToday, bool IsNotNull)
{
if (IsNotNull)
{
if (Sour == "")
{
return "日期不能为空";
}
}
else if (Sour == "")
{
return "";
}
if (IsUpToday && (Sour.CompareTo(DateTime.Now.ToString(@"yyyy//MM//dd")) < 0))
{
return "日期不能小于当前日期";
}
if (!RegDate(Sour))
{
return "日期格式不正确,应为【2002/09/06】";
}
return "";
}
/// <summary>
/// 如果格式正确则返回空,否则返回错误信息
/// </summary>
/// <param name="Sour">待测试的日期字串</param>
/// <param name="IsUpToday">是否必须大于今天</param>
/// <returns></returns>
public static string CheckDate(string Sour, bool IsUpToday)
{
return CheckDate(Sour, IsUpToday, true);
}