在密码中检查至少4个不同的字符
我需要将字符串(密码)是否包含:字母,数字,至少6个字符(长度)和(此解决问题)至少4个不同的字符。
(密码只能包含字母或数字,但至少
4个不同的字符。)到目前为止
/^\S(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/i
有
I need regex that check if a String (password) contains: letters, numbers, at least 6 character (length) AND (this going the problem) at least 4 different characters.
(Password can contains only letters or only numbers but at least 4 different char.)
So far i have been using this but this can not check at least 4 different characters
/^\S(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/i
Thx if u have any Idea
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设字符串可以包含 字母和数字,这是满足您要求的JavaScript Regex的一个示例:
Assuming the string can contain only letters and numbers, an example of a JavaScript regex that fulfills your requirements is:
如果您不介意额外的检查以使至少4个不同的角色部分更加灵活,则可以将图案与集合结合使用。
If you don't mind an extra check to make the at least 4 different characters part a bit more flexible, you can use your pattern in combination with a Set.