On 2020-12-23 17:03, Sadaka Technology wrote:
hello guys,

I have this pattern for password validation (regex):

I want these rules to be applied:

Minimum 8 characters.
The alphabets must be between [a-z]
At least one alphabet should be of Upper Case [A-Z]
At least 1 number or digit between [0-9].
At least 1 character from [ _ or @ or $ ].

and this pattern:

passwordpattern = "^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[@$])[A-Za-z\d@$!%?&]{8,}.$"

my only issue is that I want to add the symbol () and symbol(.) in the pattern 
where only it accepts $ and @, I tried adding generally like [@_$] not working

Your pattern:

^                       Matches at start of string
(?=.[a-z])              Matches any character and then one [a-z]
(?=.[A-Z])              Matches any character and then one [A-Z]
(?=.\d)                 Matches any character and then one digit
(?=.[@$])               Matches any character and then one of [@$]
[A-Za-z\d@$!%?&]{8,}        Matches 8 or more of [A-Za-z\d@$!%?&]{8,}
.                       Matches any character
$                       Matche at end of string

The pattern will never match because the second character cannot be one of [a-z] _and_ one of [A-Z] _and_ a digit _and_ one of [@$] _at the same time_.

I'm not sure what you mean by "The alphabets must be between [a-z]" (all letters lower case?) and also "At least one alphabet should be of Upper Case [A-Z]" (at least one upper case letter).

I'm guessing you mean that all letters must be [A-Za-z], but at least one of them must be [A-Z].

Also, what do you mean by "symbol () and symbol(.)"; I see the "." between the second parentheses in the second one, but nothing between the first.

Anyway, how about this pattern:

^(?=.*[A-Z])(?=.*[0-9])(?=.*[_@$])[A-Za-z0-9@$_!%?&]{8,}$

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to