luofuIT成长记录 2019-12-07
import re
def is_valid_email(addr):
#[\w]匹配至少一个数字、字母、下划线的字符;[\W]不匹配“-“”字符;“.”匹配除了\n的任意字符 pattern = re.compile(r"^[\w]+(\.[\W]+)*@+[\w]+(\.[\w])+")
result = pattern.match(addr)
if result:
return True
else:
return False
if __name__ == "__main__":
while True:
addr = input("请输入邮箱号码:\n")
if addr == "q":
break
print(is_valid_email(addr))打印信息:
请输入邮箱号码: [email protected] True 请输入邮箱号码: [email protected] True 请输入邮箱号码: [email protected] False