public class RegularExpressionsHelper { /// <summary> /// 对用户名进行格式进行检查的正则表达式 /// </summary> /// <param name="userName">输入的用户名</param> /// <returns>验证结果</returns> public static bool UserNameRegex(string userName) { string nameRegex = @"^[0-9a-zA-Z_-]{6,16}$"; return Regex.IsMatch(userName, nameRegex); } /// <summary> /// 验证手机号的正则表达式 /// </summary> /// <param name="mobilePhoneNumber">输入的手机号</param> /// <returns>验证结果</returns> public static bool MobilePhoneNumberRegex(string mobilePhoneNumber) { string phoneNumberRegex = @"^1[3578]d{9}$"; return Regex.IsMatch(mobilePhoneNumber, phoneNumberRegex); } /// <summary> /// 对邮箱进行验证的正则表达式 /// </summary> /// <param name="emial">输入的邮箱</param> /// <returns>验证结果</returns> public static bool EmailRegex(string emial) { string emailRegex = @"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$"; return Regex.IsMatch(emial, emailRegex); ; } /// <summary> /// 判断输入发字符串是否为GUID /// </summary> /// <param name="guid">输入的字符串</param> /// <returns>验证结果</returns> public static bool GuidRegex(string guid) { string guidRegex = @"^[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-Z0-9]{12}$"; return Regex.IsMatch(guid, guidRegex); } /// <summary> /// 判断输入的字符串时候为车牌号 /// </summary> /// <param name="carNumber">输入的字符串</param> /// <returns>验证结果</returns> public static bool CarNumReges(string carNumber) { string carNumReges = @"^[u4E00-u9FA5][A-Za-z][dA-za-z]{5}$"; return Regex.IsMatch(carNumber, carNumReges); } }