Skip to content
Advertisement

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.

^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,63}$

This regex will enforce these rules:

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

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

-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.

Advertisement

Answer

JavaScript

The string should not contain any symbol outside the 4 groups of characters

JavaScript

The string should not consist only of lower letters

JavaScript

The string should not consist only of upper letters

JavaScript

The string should not consist only of digits

JavaScript

The string should not consist only of special characters

JavaScript

The string should consist of 8 to 64 characters

JavaScript

UPDATED 2020-09-07

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

JavaScript

The string should not contain any symbol outside the 4 groups of characters

JavaScript

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

JavaScript

or

JavaScript

or

JavaScript

or

JavaScript

and finally the string should consist of 8 to 64 characters

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement