在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <summary> /// 验证Email地址 /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsValidEmail(string strIn) { // Return true if strIn is in valid e-mail format. //return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); return Regex.IsMatch(strIn, @"^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$", RegexOptions.IgnoreCase); } /// <summary> /// 验证是否为小数 /// [0].\d{1,2}|[1] /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsValidDecimal(string strIn) { return Regex.IsMatch(strIn, @"[0].\d{1,2}|[1]"); } /// <summary> /// 验证是否为电话号码 /// (\d+-)?(\d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8})(-\d+)? /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsValidTel(string strIn) { return Regex.IsMatch(strIn, @"(\d+-)?(\d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8})(-\d+)?"); } // <summary> /// Checks whether or not a date is a valid date. /// </summary> /// <param name="date"></param> /// <returns></returns> public static bool IsDate(string sdate) { DateTime dt; bool isDate = true; try { dt = DateTime.Parse(sdate); } catch { isDate = false; } return isDate; } /// <summary> /// 验证图片后缀名(gif,jpg,bmp,png) /// \.(?i:gif|jpg|bmp|png)$ /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsValidImgfix(string strIn) { return Regex.IsMatch(strIn, @"\.(?i:gif|jpg|bmp|png)$", RegexOptions.IgnoreCase); } /// <summary> /// 验证字符是否在6至20之间字母、数字、下划线 /// ^[a-zA-Z][a-zA-Z0-9_]{4,18}[a-zA-Z0-9]$ /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsUserName(string strIn) { return Regex.IsMatch(strIn, @"^[a-zA-Z][a-zA-Z0-9_]{4,18}[a-zA-Z0-9]$"); } /// <summary> /// 验证IP /// ^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$ /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsValidIp(string strIn) { return Regex.IsMatch(strIn, @"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$"); } /// <summary> /// 验证手机 /// ^((0)?[1][3568]([0-9]){9}) /// </summary> /// <param name="strIn"></param> /// <returns></returns> public static bool IsMobile(string strIn) { return Regex.IsMatch(strIn, @"^((0)?[1][3568]([0-9]){9})"); } |
请发表评论