Need a Regular Expression
for Passwords which must have an :
- 8 characters minimum
- Must include at least two of the following
- lowercase letters
- uppercase letters
- numbers and
- symbols
- Character limit of 50
Need a Regular Expression
for Passwords which must have an :
Thank you all for your time. After multiple tries, following pattern works for me:
Note: Following expression checks "2 each" of (uppercase, lowercase, 0-9)
otherwise,
And, following checks "any 2" of (uppercase, lowercase, 0-9, defined set of specials symbols)
Description:
(?=.{8,50}$)
(?= ANDs the condition to rest of conditions that follows), this condition checks for length of input from 8 to 50(?=(.*[A-Z]){2})
(where, .* any character 0 or more times, followed by UPPERCASE letter) and {2}, means by condition should apply two times, therefore UPPERCASE letter exists 2 times(?=(.*[a-z]){2})
(where, .* means any character 0 or more times, followed by LOWERCASE letter) and {2}, means by condition should apply two times, therefore LOWERCASE letter exists 2 times(?=(.*[0-9]){2})
(where, .* means any character 0 or more times, followed by DIGIT ) and {2}, means by condition should apply two times, therefore DIGIT exists 2 times(?=\\S+$)
(where, \S means there non-whitspace, + means 0 or more times, so it checks if all characters are non white space characters. So if a space comes this condition will fail.NOTE:"\" I used for java escape character
.*
this is last condition, which means any other character after my last check (e.g digit in my case, so it is not must, that last character should be digit.NOTE: If there is only 1 or last condition, we don't use ?= to AND.
In java I tried this small program:
This regex will work for Unicode characters as well.
You can use the regex as below:
Debuggex Demo
What I tried is combination of :
For more from jsBin you could look into JsBin Demo
You could also look into
@areschen
answer, the JsBin is inspired from his fiddle.For Reference :
Regex : Atleast 2 digits and 1 special char. Regex : I want this & that - As pointed by @Barmar