This question already has an answer here:
Validating Password using Regex
                                
                                    (1个答案)
                                
                        
                                5年前关闭。
            
                    
我想使用以下规则在C编程中验证密码。


至少一个大写单词
至少一个小写字母
至少一个数字
至少一个符号(!@#$%^&*)
长度:8-32


如何使用正则表达式或不使用正则表达式呢?

最佳答案

您可以尝试使用以下正则表达式来满足您的所有要求,

^(?=.{8,32}$)(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[(!@#$%^&*)]).*


DEMO

^(?=.{8,32}$)         -      length: 8 - 32
(?=.*?[A-Z])          -      at-least one uppercase letter.
(?=.*?[a-z])          -      at-least one lowercase letter.
(?=.*?[0-9])          -      at-least one number.
(?=.*?[(!@#$%^&*)])   -      at-least one symbol present inside the character class.
.*                    -      Match any character zero or more times only if all the above 5 conditions are true.

关于c - C编程中的验证密码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25601734/

10-15 16:35