数据有效性检查
#region 数据有效性检查
//判断区号
public static bool IsAreaCode(string input)
{
return ((IsNumber(input) && (input.Length >= 3)) && (input.Length <= 5));
}
//判断是否为正Decimal
public static bool IsDecimal(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, "^[0-9]+[.]?[0-9]+$");
}
//判断是否为Decimal
public static bool IsDecimalSign(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, "^[+-]?[0-9]+[.]?[0-9]+$");
}
//是否为EMail
public static bool IsEmail(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
}
//是否为IP
public static bool IsIP(string input)
{
return (!string.IsNullOrEmpty(input) && Regex.IsMatch(input.Trim(), @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"));
}
//是否为正整数
public static bool IsNumber(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, "^[0-9]+$");
}
//是否为整数
public static bool IsNumberSign(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, "^[+-]?[0-9]+$");
}
//是否邮编
public static bool IsPostCode(string input)
{
return (IsNumber(input) && (input.Length == 6));
}
//是否为网址
public static bool IsUrl(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
return Regex.IsMatch(input, @"^http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$");
}
#endregion
#region 日期函数