.net正则验证

/// <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 = "验证失败" };
        }

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。