码迷,mamicode.com
首页 > Web开发 > 详细

.net正则验证

时间:2015-05-04 19:47:20      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
        /// 验证手机号
        /// </summary>
        /// <param name="telNum"></param>
        /// <returns></returns>
        private static dynamic CheckTelNum(string telNum)
        {
            Regex mobileRegex = new Regex("^[0-9]{11,11}");

            if (mobileRegex.IsMatch(telNum))
            {
                return new {isTrue = true, message = "验证通过"};
            }
            return new {isTrue = false, message = "验证失败"};
        }

        /// <summary>
        /// 验证邮箱
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        private static dynamic CheckEmail(string email)
        {
            bool result = Regex.IsMatch(email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

            if (result) return new { isTrue = true, message = "验证通过" };
            return new { isTrue = false, message = "验证失败" };
        }

        /// <summary>
        /// 验证数字
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        private static dynamic CheckIntNum(string num)
        {
            Regex mobileRegex = new Regex("^[0-9]");

            if (mobileRegex.IsMatch(num))
            {
                return new { isTrue = true, message = "验证通过" };
            }
            return new { isTrue = false, message = "验证失败" };
        }

  

.net正则验证

标签:

原文地址:http://www.cnblogs.com/xiguain/p/4476944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!