C#正则验证
1.验证double正浮点类型
//验证正浮点型 private readonly Regex doubleX= new Regex(@"^\+?[0-9]*(\.[0-9]*)?([Ee][-+]?[0-9]+)?$", RegexOptions.IgnoreCase | RegexOptions.Compiled); //验证100以内的正浮点型 private readonly Regex doubleX100 = new Regex(@"^(((\d|[1-9]\d)(\.\d{1,2})?)|100|100.0|100.00)$");
2.验证电话号码
[RegularExpression(@"^(0[0-9]{2,3}\-)([2-9][0-9]{6,7})?(\-[0-9]{1,4})?$|(^(13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$)", ErrorMessage = "请输入正确的手机号码!")]
3.邮箱验证
[RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "请输入正确的邮箱!")]
4.中文验证方式
#region 验证 /// <summary> /// 验证是否文中文 [正确true/错误false] /// </summary> public static bool GetBoolChinese(string str) { if (str == "" || str == null) { return false; } else { var r = new Regex(@"[\u4e00-\u9fa5]"); if (r.IsMatch(str)) { return true; } else { return false; } } } #endregion