如何使用正则表达式检查密码复杂性? [英] How do I check for password complexity using regex?
问题描述
我需要一个正则表达式来检查以下内容:
1.至少8个字符
2.至少落入三个以下四类:
- 至少一个大写字符
- 至少一个小写字符
- 至少一个数字
- 至少一个特殊字符
我在C#.NET工作,并在服务器端进行密码复杂性检查(从网格中) 。但是,如果用户填写了50个密码框而其中一个不符合复杂性,则所有密码框都将被清除。所以,我正在寻找一个客户端解决方案(或任何其他可行的选项)。
谢谢!
I need a regex that checks for the following:
1. At least 8 characters
2. Falls into at least three of the following four categories:
- At least one uppercase character
- At least one lowercase character
- At least one number
- At least one special character
I'm working in C#.NET and was doing password complexity check (from a grid) on the server side. However, if the user fills in 50 password boxes and one doesn't meet complexity, all are wiped out. So, I'm looking for a client solution (or any other viable option).
Thanks!
推荐答案
使用Regex对许多验证非常有用,对于测量复杂性并不是一个好主意。问题很简单。有关解决方案,请参阅我过去的答案:
如何在C#.net 中验证有效密码[ ^ ],
正则表达式验证密码 [ ^ ]。
简单,不是不是吗?
-SA
Using Regex, very useful for many validations, is not a good idea for measuring complexity. The problem is very simple. For a solution, please see my past answers:
how to authenticate Valid password in C#.net[^],
regular expression to validate the password[^].
Simple, isn't it?
—SA
请尝试以下正则表达式。
(?!^ [0-9] *
Try below Regular expression.
(?!^[0-9]*
)(?!^ [a-zA-Z] *
)(?!^[a-zA-Z]*
这篇关于如何使用正则表达式检查密码复杂性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!