首页 > 其他 > 详细

正则表达式验证

时间:2014-09-15 17:16:39      阅读:286      评论:0      收藏:0      [点我收藏+]
 public class RegularHelp
    {

        //验证Email地址
        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})(\]?)$");
        }

        //验证是否为电话号码
        public static bool IsValidTel(string strIn)
        {
            return Regex.IsMatch(strIn, @"(d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?");
        }

        //验证手机号
        public static bool IsValidPhone(string strIn)
        {
            return Regex.IsMatch(strIn, @"^[1][345789]\d{9}$");
        }

        //验证登录名
        public static bool IsVaildLoginName(string strIn)
        {
            return Regex.IsMatch(strIn, @"^[a-zA-Z]{1}[a-zA-Z0-9_]{5,15}$");
        }

        //验证密码
        public static bool IsVaildPassword(string strIn)
        {
            return Regex.IsMatch(strIn, @"^[A-Za-z0-9!@#$%^&*~]{6,22}$");

        }
    }

 

正则表达式验证

原文:http://www.cnblogs.com/llxy/p/3972939.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!