using System.Text.RegularExpressions;
namespace Ant.Service.Common
{
///
/// 操作正则表达式的公共类
///
public class RegexHelper
{
#region 验证输入字符串是否与模式字符串匹配
///
/// 验证输入字符串是否与模式字符串匹配,匹配返回true
///
/// 输入字符串
/// 模式字符串
public static bool IsMatch(string input, string pattern)
{
return IsMatch(input, pattern, RegexOptions.IgnoreCase);
}
///
/// 验证输入字符串是否与模式字符串匹配,匹配返回true
///
/// 输入的字符串
/// 模式字符串
/// 筛选条件
public static bool IsMatch(string input, string pattern, RegexOptions options)
{
return Regex.IsMatch(input, pattern, options);
}
///
/// 判断邮箱是否合法
///
///
///
bool IsEmail(string email)
{
Regex regex = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
//var regex = new Regex(@"^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
return regex.IsMatch(email);
}
#endregion
}
}