I have password validation by regex. This is my expression:
^ (?. * \ D) (? =. * [Az]) (? =. * [AG]) (? =. * [@ # $ % ^ & Amp; + =]). * $
This works - the password must contain at least 1 digit, at least 1 lower case letter, at least 1 uppercase letter and at least special characters : @ # $% ^ & amp; + =
. So I have to input all these characters.
But I want a password, which has at least 3 combinations, not 4. 4. Then this password should be good:
2 DF
(not a special character), DF #
(not number), a4%
(no upper case). I would like to ask, how should this Rezek expression be shown? I can write each expression to check each combination, for example:
- Do not include numbers:
^ (? =. * [Az]) (? =. * [AZ]) (? =. * [@ # $% ^ & Amp; + =]) * $
- The upper case is not included:
^ (? =. * \ D) (? =?. * [AG]) (? =. * [@ # $ % ^ & Amp; + =]). * $
But maybe I can do it in an expression.
If you want to do it with regular expression, then I suggest (for clarity) a Check the other four conditions after the second For readability, you can first try to find \ d
in your code, then [az]
, then [Az]
and then [@ # $% ^ & amp; + =]
(though you want to use [\ w_]
, rather than those few additional characters) then check that at least three of these work.
If you is to do this in a single regex, then you can use the alternation:
? ^ ((= * [Az]) (= * [AZ]) (= * \ d) |.?.?.?.? (= * [Az]) (= * [AZ]) (=. * [\ W_]) | (= * [\ w_]) (= * [AZ]) (= * \ d) |?.?.?.?.. (= * [Az]) (= * [\ W_]) (? =? * \ D \)). * $
But this is just ugly.
Comments
Post a Comment