public static class Verify { /// <summary> /// 验证手机号码 /// </summary> /// <param name="str_handset"></param> /// <returns></returns> public static bool IsHandset(string str_handset) { return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"(^1[3456789]\d{9}$)"); } /// <summary> /// 验证身份证号 /// </summary> /// <param name="str_idcard"></param> /// <returns></returns> public static bool IsIDcard(string str_idcard) { return System.Text.RegularExpressions.Regex.IsMatch(str_idcard, @"(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)"); } /// <summary> /// 验证输入为数字 /// </summary> /// <param name="str_number"></param> /// <returns></returns> public static bool IsNumber(string str_number) { return System.Text.RegularExpressions.Regex.IsMatch(str_number, @"^[0-9]*$"); } /// <summary> /// 验证邮编 /// </summary> /// <param name="str_postalcode"></param> /// <returns></returns> public static bool IsPostalcode(string str_postalcode) { return System.Text.RegularExpressions.Regex.IsMatch(str_postalcode, @"^\d{6}$"); } /// <summary> /// 验证邮箱 /// </summary> /// <param name="str_Email"></param> /// <returns></returns> public static bool IsEmail(string str_Email) { return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"^([a - zA - Z0 - 9_ -]) +@([a - zA - Z0 - 9_ -]) + ((.[a-zA - Z0 - 9_ -]{ 2,3}){ 1,2})$"); } }
标签:Regex,string,邮箱地址,c#,System,static,str,public,邮编 From: https://www.cnblogs.com/tlfe/p/18242614