[英]Password regex that requires “at least two of” certain characters
Im working on javascript regex which includes having following conditions.我正在研究 javascript 正则表达式,其中包括具有以下条件。 So far with no luck.
到目前为止没有运气。
-The minimum character count allowed is 8. - 允许的最小字符数为 8。
-The maximum character count allowed is 64. - 允许的最大字符数为 64。
-The entered text should include at least two of the following - numbers, lowercase letters, uppercase letters, Special characters. - 输入的文本应至少包含以下两项 - 数字、小写字母、大写字母、特殊字符。
-Entering symbols will not be supported. - 不支持输入符号。
So far what I have is this @anubhava answer here .到目前为止,我有什么是这个@anubhava答案在这里。
^(?=.*?[AZ])(?=.*?[az])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,63}$
This regex will enforce these rules:此正则表达式将强制执行以下规则:
-At least one upper case English letter, (?=.*?[AZ]) - 至少一个大写英文字母,(?=.*?[AZ])
-At least one lower case English letter, (?=.*?[az]) -至少一个小写英文字母,(?=.*?[az])
-At least one digit, (?=.*?[0-9]) - 至少一位,(?=.*?[0-9])
-At least one special character, (?=. ?[#?!@$%^& -]) - 至少一个特殊字符,(?=. ?[#?!@$%^& -])
-Minimum eight in length .{8,63} (with the anchors) - 长度至少为 8 .{8,63}(带锚点)
My Question is how do I satify my 3rd and 4th conditions Which is :-我的问题是如何满足我的第三个和第四个条件,即:-
-The entered text should include at least two of the following - numbers, lowercase letters, uppercase letters, Special characters. - 输入的文本应至少包含以下两项 - 数字、小写字母、大写字母、特殊字符。
-Entering symbols will not be supported. - 不支持输入符号。
Any help would be appreciated.任何帮助,将不胜感激。
var regex =/^(?=.*\\d)(?=.*[!@#$%^&*])(?=.*[az])(?=.*[AZ]).{8,64}$/; function test() { if(regex.test(document.getElementById("txtPassword").value)===false) { alert("Min 8,Max 64,At Least One Uppercase Character,One Lowercase Character,One Numeric Value And One Special Character(!@#$%^&*) Required "); } else { alert("Success"); } }
<input type="text" id="txtPassword" /> <button id="testBtn" onclick=test()>CheckPassword</button>
^(?!.*[^A-Za-z0-9#?!@$%^&*-]$)(?![a-z]*$)(?![A-Z]*$)(?![0-9]*$)(?![#?!@$%^&*-]*$).{8,64}$
The string should not contain any symbol outside the 4 groups of characters字符串不应包含 4 组字符之外的任何符号
^(?!.*[^A-Za-z0-9#?!@$%^&*-]$)
The string should not consist only of lower letters字符串不应只包含小写字母
(?![a-z]*$)
The string should not consist only of upper letters字符串不应仅由大写字母组成
(?![A-Z]*$)
The string should not consist only of digits字符串不应仅由数字组成
(?![0-9]*$)
The string should not consist only of special characters字符串不应仅包含特殊字符
(?![#?!@$%^&*-]*$)
The string should consist of 8 to 64 characters字符串应包含 8 到 64 个字符
.{8,64}$
^(?!.*[^A-Za-z0-9#?!@$%^&*-]$)((?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])|(?=.*[a-z])(?=.*[A-Z])(?=.*[#?!@$%^&*-])|(?=.*[a-z])(?=.*[0-9])(?=.*[#?!@$%^&*-])|(?=.*[A-Z])(?=.*[0-9])(?=.*[#?!@$%^&*-])).{8,64}$
The string should not contain any symbol outside the 4 groups of characters字符串不应包含 4 组字符之外的任何符号
^(?!.*[^A-Za-z0-9#?!@$%^&*-]$)
Then 4 variants of 3 groups of 4 that the symbols should be member of:然后是符号应该是成员的 3 组 4 组的 4 个变体:
(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])
or或者
(?=.*[a-z])(?=.*[A-Z])(?=.*[#?!@$%^&*-])
or或者
(?=.*[a-z])(?=.*[0-9])(?=.*[#?!@$%^&*-])
or或者
(?=.*[A-Z])(?=.*[0-9])(?=.*[#?!@$%^&*-])
and finally the string should consist of 8 to 64 characters最后字符串应该由 8 到 64 个字符组成
.{8,64}$
Text includes at least two of the following - numbers, lowercase letters, uppercase letters, Special characters.文本至少包括以下两项- 数字、小写字母、大写字母、特殊字符。 No characters outside [A-Za-z0-9#?!@$%^&*-]
[A-Za-z0-9#?!@$%^&*-] 之外没有字符
^(?=.*?[A-Z])(?=.*?[a-z])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[A-Z])(?=.*?[0-9])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[A-Z])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[a-z])(?=.*?[0-9])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[a-z])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[0-9])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$
Text includes at least three of the following - numbers, lowercase letters, uppercase letters, Special characters.文本至少包括以下三个- 数字、小写字母、大写字母、特殊字符。 No characters outside [A-Za-z0-9#?!@$%^&*-]
[A-Za-z0-9#?!@$%^&*-] 之外没有字符
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$|^(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])(?!.*?[^A-Za-z0-9#?!@$%^&*-]).{8,63}$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.