2020-12-28 14:55:48 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Hncore.Infrastructure.Common
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class RegexPattern
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string Mobile = @"^1[123456789]\d{9}$";//宽松的手机验证。包含运营商可能的新增号段。
|
|
|
|
|
|
public const string Email = @"^[\w-]+@[\w-]+\.(com|net|org|edu|mil|tv|biz|info)$";// 邮箱验证
|
|
|
|
|
|
public const string IdCard = @"^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$";//18位身份证
|
|
|
|
|
|
public const string CarNumber = @"^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})$";
|
|
|
|
|
|
public static bool IsMatch(string str,string pattern)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Regex.IsMatch(str, pattern);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsMobile(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsMatch(str, Mobile);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsEmail(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsMatch(str, Email);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsIdCard(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsMatch(str, IdCard);
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsCarNumber(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IsMatch(str, CarNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|