密码强度验证的正则表达式问题
我正在寻找一个满足我们的密码要求的正则表达式。密码:
- 必须至少为 8 个字符
- 不能包含空格
- 同时包含小写和大写字符
- 包含至少一个数字
- 包含至少一个特殊字符(即除
0-9,az,AZ
以外的任何字符)
I'm looking for a single regular expression for our password requirements. Passwords:
- Must be at least 8 characters
- Cannot contain spaces
- Contain both lowercase and UPPERCASE characters
- Contain at least one numeric digit
- Contain at least one special character (i.e. any character not
0-9,a-z,A-Z
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写逻辑代码可能会更容易。正则表达式用于匹配模式。密码往往是随机的字符串,因此该问题不容易通过正则表达式解决。这是可能的,但阅读起来会很神秘并且难以维护。
It'll probably be easier to code the logic. Regex is used for matching patterns. Passwords tend to be somewhat random strings, so the problem doesn't lend itself easily to be solved by a regex. It's possible but will be cryptic to read and hard to maintain.
想法和大部分工作取自 http: //www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/
我在他的帖子底部使用了基本答案,但用
\S
排除空格字符,并移动了一些断言。Idea and most of the work taken from http://www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/
I used the basic answer at the bottom of his post, but replaced all the dots with
\S
to rule out space characters, and moved around some of the assertions.