C#常用正则表达式
using System.Text.RegularExpressions;
namespace Common
{
///
/// 检查输入的判断
///
public static class ValidateInput
{
//是否是数字
public static bool IsInteger(string txt)
{
Regex objRegex = new Regex(@"[1]$");
return objRegex.IsMatch(txt);
}
//是否是邮箱地址
public static bool IsEmail(string txt)
{
Regex objRegex = new Regex(@"^\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)$");
return objRegex.IsMatch(txt);
}
//是否是手机号码
public static bool IsMobile(string txt)
{
Regex objRegex = new Regex(@"[2][3578]\d{9}$");
return objRegex.IsMatch(txt);
}
//是否是汉字
public static bool IsChinese(string txt)
{
Regex objRegex = new Regex(@"[3]{0,}$");
return objRegex.IsMatch(txt);
}
}
}