正则判断字符串必须包含大小写字母数字

时间:2021-04-10 00:14:28
def judge_password(password):
    if len(password) >= 8:
        pattern = re.compile('[A-Z]+')
        match = pattern.findall(password)
        if match:
            pattern = re.compile('[a-z]+')
            match = pattern.findall(password)
            if match:
                pattern = re.compile('[0-9]+')
                match = pattern.findall(password)
                if match:
                    return 'True'
                else:
                    return '必须包含数字'
            else:
                return '必须包含小写字母'
        else:
            return '必须包含大写字母'
    else:
        return '长度必须大于8位'