大小写字母,特殊字符,数字,八位及以上四选三,全符合验证

大小写字母,特殊字符,数字至少八位以上验证

正则表达式:    ^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$

拆分解释:

               (1)^匹配开头

    (2)(?![A-Za-z0-9]+$)匹配后面不全是(大写字母或小写字母或数字)的位置,排除了(大写字母、小写字母、数字)的1种2种3种组合

    (3)(?![a-z0-9\\W]+$)同理,排除了(小写字母、数字、特殊符号)的1种2种3种组合

    (4)(?![A-Za-z\\W]+$)同理,排除了(大写字母、小写字母、特殊符号)的1种2种3种组合

    (5)(?![A-Z0-9\\W]+$)同理,排除了(大写字母、数组、特殊符号)的1种2种3种组合

    (6)[a-zA-Z0-9\\W]匹配(小写字母或大写字母或数字或特殊符号)因为排除了上面的组合,所以就只剩下了4种都包含的组合了

    (7){8,}8位以上

    (8)$匹配字符串结尾

扫描二维码关注公众号,回复: 8459281 查看本文章
string testString1 = "a1234567";//小写字母,数字
            string testString2 = "A1234567";//大写字母,数字
            string testString3 = "aB123456";//大小写字母,数字
            string testString4 = ".1234567";//特殊字符,数字
            string testString5 = "!@#$%^&a";//特殊字符,小写字母
            string testString6 = "!@#$%^&B";//特殊字符,大写字母
            string testString7 = "aB!@#$%^&";//特殊字符,大小写字母
            string testString8 = "B!@#$%^12";//特殊字符,数字,大写字母
            string testString9 = "a!@#$%^12";//特殊字符,数字,小写字母
            string testString10 = "aB!@#$%^12";//特殊字符,数字,大小写字母
            Regex regexMatch = new Regex("^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$");
            Console.WriteLine("小写字母,数字测试:"+regexMatch.IsMatch(testString1));
            Console.WriteLine("大写字母,数字测试:" + regexMatch.IsMatch(testString2));
            Console.WriteLine("大小写字母,数字测试:" + regexMatch.IsMatch(testString3));
            Console.WriteLine("特殊字符,数字测试:" + regexMatch.IsMatch(testString4));
            Console.WriteLine("特殊字符,小写字母测试:" + regexMatch.IsMatch(testString5));
            Console.WriteLine("特殊字符,大写字母测试:" + regexMatch.IsMatch(testString6));
            Console.WriteLine("特殊字符,大小写字母测试:" + regexMatch.IsMatch(testString7));
            Console.WriteLine("特殊字符,数字,大写字母测试:" + regexMatch.IsMatch(testString8));
            Console.WriteLine("特殊字符,数字,小写字母测试:" + regexMatch.IsMatch(testString9));
            Console.WriteLine("特殊字符,数字,大小写字母测试:" + regexMatch.IsMatch(testString10));


特殊字符,大小写字母,数字四选三组合至少八位

 正则表达式   ^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_]+$)(?![a-z0-9]+$)(?![a-z\\W_]+$)(?![0-9\\W_]+$)[a-zA-Z0-9\\W_]{8,}$

猜你喜欢

转载自www.cnblogs.com/TechSingularity/p/12165992.html