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 = "请输入正确的邮箱!")]

 

转载于:https://www.cnblogs.com/dzw159/p/11287066.html

你可能感兴趣的:(C#正则验证)