import re
def checkPassword(password):
if len(password) != 8:
return '密码长度必须为八位!'
elif re.match('^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$', password):
return '密码正确'
else:
return '密码必须包含大小写,数字!'
password = '1qQqq13'
print(checkPassword(password))
import re
def checkPassword(password):
if re.match('^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$', password):
return '密码正确'
else:
return '密码必须包含大小写,数字!'
password = '1qQqq13'
print(checkPassword(password))
用re模块search 判断密码规则正确与否的方法!
import re
def checkPassword(password):
passwordRegex = re.compile(r'^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8}$')
moPassword = passwordRegex.search(password)
if moPassword == None:
return '密码必须包含大小写,数字。'
else:
return '密码正确'
password = '1wWqq133'
print(checkPassword(password))
*(?=.[0-9])
任意字符串后有一数字
(?=.*[a-z])
任意字符串后有一小写字母
(?=.*[A-Z])
任意字符串后有一大写字母**