简体   繁体   中英

Password regex that requires “at least two of” certain characters

Im working on javascript regex which includes having following conditions. So far with no luck.

-The minimum character count allowed is 8.

-The maximum character count allowed is 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 .

^(?=.*?[AZ])(?=.*?[az])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,63}$

This regex will enforce these rules:

-At least one upper case English letter, (?=.*?[AZ])

-At least one lower case English letter, (?=.*?[az])

-At least one digit, (?=.*?[0-9])

-At least one special character, (?=. ?[#?!@$%^& -])

-Minimum eight in length .{8,63} (with the anchors)

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

^(?!.*[^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}$

UPDATED 2020-09-07

If the string should contain symbols of at list 3 groups of 4

^(?!.*[^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

^(?!.*[^A-Za-z0-9#?!@$%^&*-]$)

Then 4 variants of 3 groups of 4 that the symbols should be member of:

(?=.*[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}$

Text includes at least two of the following - numbers, lowercase letters, uppercase letters, Special characters. No characters outside [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-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}$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM