a.提示用户输入邮箱地址,如果用户输入的邮箱地址不符合规范,告诉用户重新输入
(1)邮箱地址用户名部分是一个或多个字符,字符可以包括:小写和大写字母,数字,句点,下划线,百分号,加号,或者短横。
(2)用@符号分割
(3)域名只允许字母,数字,句号和短横,可以有2到4个字符。
b.用户输入了正确格式的email以后,如果它输入的是qq.com域名,则打印“我也用qq邮箱“
c.提示用户输入密码
(1)密码长度要求大于8个字符
(2)密码需要包含至少一个小写字母,至少一个大写字母,至少一个数字,至少一个特殊字符
(3)特殊字符为:@,#,$,%,&,^,* (英语输入法下的特殊字符) 如果用户输入的密码不符合要求,告知用户哪些个要求不满足,并要求用户重新输入
import re
pat = r'^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$'
email_address = input('输入邮箱地址')
matched_address = re.match(pat, email_address)
if matched_address:
print(matched_address.group())
else:
print('邮箱地址不符合规范')
if 'qq.com' in email_address:
print('我也用qq邮箱')
paw = r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
password = input('输入密码')
matched_password = re.match(paw, password)
if matched_password:
print(matched_password.group())
else:
print('密码不符合要求')
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢
import re
from typing import Pattern
while True:
email=input("请输入一个邮箱地址:")
check=r"[a-zA-Z0-9._-%+]@[a-zA-Z0-9.-]{2,4}.com"
checkmail=re.compile(check)#编译
result = checkmail.findall(email)#findall匹配整个子串,search只匹配一个子串即返回值
if result:
print("邮箱格式正确")
t=re.findall(r"qq.com",email,re.I)#re.I忽略大小写
if t:
print("我也用qq邮箱")
else:
print("您输入的邮箱地址不符合规矩,请重新输入")
continue
while True:
password=input("请输入密码:")
checkword1=re.compile("[a-z]")#匹配小写字母
checkword2=re.compile("[A-Z]")#匹配大写字母
checkword3=re.compile("[0-9]")#匹配数字
checkword4=re.compile("[@#$%&^*]")#匹配数字
#以下为判定条件
if len(password)<8:
print("你的密码小于8位,请重新输入")
elif checkword1.search(password)==None :
print("你的密码缺少小写字母,请重新输入:")
elif checkword2.search(password)==None :
print("你的密码缺少大写字母,请重新输入:")
elif checkword3.search(password)==None :
print("你的密码缺少数字,请重新输入:")
elif checkword4.search(password)==None :
print("你的密码缺少特殊字符,请重新输入:")
else:
print("密码正确,登录成功!")
break
while True:
phoneNumber = input("请输入联系电话:")
checknumber = r"(\(?(\+\d{2})?\)?)\s*-?(\d{3})\-?(\d{4})\-?(\d{4})|(\(?\d{4}\)?)\s*\-?(\d{8})"
checkphone = re.compile(checknumber)
checkphoneNumber = checkphone.findall(phoneNumber)
#判断手机号格式是否正确
if checkphoneNumber:
print(phoneNumber)
else:
print("您输入的格式不正确,手机号码为11位;固定电话区号4位,号码为8位")
#预先处理固定电话号码,固定电话号码为12位
if len(phoneNumber)==12:
fix = r"\(?(\d{4})\)?\s*\-?(\d{8})"
checkfix = re.compile(fix)
checkfrontfixed = checkfix.sub(r"\1",phoneNumber)#提取固定号码前四位进行匹配
if checkfrontfixed == "0512":
print("你的固定地址在苏州")
else:
print("你使用的是非苏州固定地址")
else:
mobile = r"\(?(\+\d{2})?\)?\s*-?(\d{3})\-?(\d{4})\-?(\d{4})"
checkphone1 = re.compile(mobile)
checkmobile = checkphone1.sub(r"\2\3\4",phoneNumber)#先进行替换,去掉手机号码的域名
Pattern=r"(\d{3})(\d{8})"#提取前三位进行运营商匹配
frontmobile=re.compile(Pattern)
checkfront = frontmobile.sub(r"\1",checkmobile)
# print(checkmobile)
# print(checkfront)用于查看提取是否正确
if checkfront=="176" or checkfront=="175":
print("你使用的是联通运营商")
if checkfront=="173" or checkfront=="177":
print("你使用的是电信运营商")
if checkfront=="172" or checkfront=="178":
print("你使用的是移动运营商")
if checkfront!="176" or checkfront!="175" or checkfront!="173" or checkfront!="177" or checkfront!="172" or checkfront!="178":
print("你使用的是非三大运营商")
print("邮箱为:"+email+"密码为:"+password+"联系电话为:"+phoneNumber)#输出邮箱密码及联系电话
break
break
import re
a = ''
while re.match('^[a-zA-Z0-9\._]+@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$',a)==None:
a = input('请输入正确的信箱地址:')
print(a)
if re.match('^[a-zA-Z0-9\._]+@qq.com$',a)!=None:
print('我也用qq信箱')
b = ''
while re.match('^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[@#$%^*]).{8,}',b)==None:
b = input('请输入密码:')
print(b)