用于密码验证的正则表达式
我想验证密码。以下是我的要求。
最小密码长度:8
最小小写字符数:1
最小大写字符数:1
最小数字字符数:1
如何为此编写正则表达式?
I want to validate password .The following are my requirements.
Minimum password length: 8
Minimum number of lower case characters: 1
Minimum number of upper case characters: 1
Minimum number of numeric characters: 1
How to write a regex for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下正则表达式:
You can use the following regex:
我同意@Russell,函数是密码验证的更好选择。很难想象单个正则表达式可以处理所有这些情况。我认为您必须依次检查每一项。
单独而言,正则表达式为:
.{8}
匹配至少 8 个字符[az]
匹配单个小写字符[AZ]
匹配单个大写字符[0-9]
匹配数字 话虽如此,这些仅对服务器进行深入验证之前的客户端检查有用。
I agree with @Russell, a function is a better choice for password validation. And it's hard to imagine a single Regex handling all these cases. I think you would have to check each one in turn.
Individually, the Regex expressions are:
.{8}
matches at least 8 characters[a-z]
matches a single lowercase character[A-Z]
matches a single uppercase character[0-9]
matches a digitThat having been said, these would only be useful for client-side checking prior to having the server do in-depth validation.
请查找以下正则表达式以满足您的要求:
Please find below regex for your requirements: