python3 用正则判断输入的密码是否符合要求
下面代码接受输入一串字符作为密码,并用正则判断密码是否符合要求:1.必须大于或等于8个字符;2.必须同时包含大小写字母和数字;3.不接受除字母和数字以外的字符。不符合要求时打印相应的提示。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#! python3
# coding=utf-8
import re
lowerRegex = re.compile('[a-z]')
upperRegex = re.compile('[A-Z]')
digitRegex = re.compile('[0-9]')
wrongRegex = re.compile('[^a-zA-Z0-9]')
while True:
password = input('请输入大于8位的包含大小写字母和数字的密码:')
if len(password) < 8:
print('输入的密码小于8位')
elif wrongRegex.search(password) != None:
print('包含无效字符')
else:
if lowerRegex.search(password) == None:
print('未包含小写字母')
elif upperRegex.search(password) == None:
print('未包含大写字母')
elif digitRegex.search(password) == None:
print('未包含数字')
else:
print('输入成功')
break
最后
以上就是跳跃面包最近收集整理的关于python3 用正则判断输入的密码是否符合要求python3 用正则判断输入的密码是否符合要求的全部内容,更多相关python3内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复