Regex to check string for unique characters and prohibited characters
I'm writing a password validation regex and I've managed to get 80-90% of the way there but can't incorporate the last two pieces I need and I'm sick of beating my head against the wall so that's where you guys come in ;)
Here is my expression so far:
^(?!.*(.)\1{3}).*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[\Q~!@#$%^&*()-_=+[]{}|;:,.<>/?\E]).*$
so in order I have the following rules:
(?!.*(.)\1{3})
- no more than 3 of the same character in sequence.*(?=.{8,})
- string must be a minimum of 8 characters(?=.*\d)
- must contain at least one digit(?=.*[a-z])
- must contain at least one lower case letter(?=.*[A-Z])
- must contain at least one upper case letter(?=.\*[\Q~!@#$%^&*()-_=+[]{}|;:,.<>/?\E])
- must contain at least one of these special characters
I need to add two more restrictions
1) no character other than an alphanumeric or one of my special characters may appear in the string. So I think I have the basic expression correct:
^([\w\Q~!@#$%^&*()-_=+[]{}|;:,.<>/?\E]*)$
but when I try to add that into my overall expression it doesn't work or it screws up one of my other conditions, so I'开发者_运维技巧m not sure what I'm doing wrong
2) the string MUST contain 4 unique characters. I cant figure this one out at all.
thanks in advance for any help you can provide
Try this one. (I removed a couple of .*
s which aren't needed and removed the minimum of 8 chars because that can be incorporated in the final piece.)
^
(?!.*(.)\1{3})
(?=.*\d)
(?=.*[a-z])
(?=.*[A-Z])
(?=.*[\Q~!@#$%^&*()-_=+[]{}|;:,.<>/?\E])
[\w\Q~!@#$%^&*()-_=+[]{}|;:,.<>/?\E]{8,}
$
Also, your last rule:
the string MUST contain 4 unique characters.
Is already checked for, because you are requesting one digit, one upper, one lower, and one special = four different classes.
精彩评论