using System;
using System.Text.RegularExpressions;
namespace WX.CRM.WebHelper
{
///
/// 数据验证
///
public class ValidateHelper
{
private static Regex RegNumber = new Regex("^[0-9]+$");
private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");
private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");
private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$");
private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$");
private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");
#region 数字字符串检查
///
/// 是否数字字符串
///
/// 输入字符串
///
public static bool IsNumber(string inputData)
{
if (!string.IsNullOrEmpty(inputData))
{
Match m = RegNumber.Match(inputData);
return m.Success;
}
else
{
return false;
}
}
///
/// 是否数字字符串 可带正负号
///
/// 输入字符串
///
public static bool IsNumberSign(string inputData)
{
Match m = RegNumberSign.Match(inputData);
return m.Success;
}
///
/// 是否是浮点数
///
/// 输入字符串
///
public static bool IsDecimal(string inputData)
{
Match m = RegDecimal.Match(inputData);
return m.Success;
}
///
/// 是否是浮点数 可带正负号
///
/// 输入字符串
///
public static bool IsDecimalSign(string inputData)
{
Match m = RegDecimalSign.Match(inputData);
return m.Success;
}
#endregion
#region 中文检测
///
/// 检测是否有中文字符
///
///
///
public static bool IsHasCHZN(string inputData)
{
Match m = RegCHZN.Match(inputData);
return m.Success;
}
#endregion
#region 邮件地址
///
/// 是否是浮点数 可带正负号
///
/// 输入字符串
///
public static bool IsEmail(string inputData)
{
Match m = RegEmail.Match(inputData);
return m.Success;
}
#endregion
#region 是否是时间格式
///
/// 判断一个字符串是否时间格式
///
/// 输入字符串
///
public static bool IsDateTime(string inputData)
{
try
{
Convert.ToDateTime(inputData);
return true;
}
catch
{
return false;
}
}
#endregion
}
}