正则验证邮箱正确性
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
相关推荐
mmyCSDN 2020-02-10
stulen 2020-01-21
hedongli 2019-12-31
huzai 2015-04-22
sdnxiaotao 2019-04-02
精通正则表达式 2013-09-23
89203856 2013-04-27
peterwzc 2011-11-23
Gyc 2011-09-08
Lucianoesu 2014-09-01
CommputerMac 2017-01-20
87941037 2017-12-05
zlxcsdn 2017-12-11
差沙 2016-05-09
前端档案 2015-11-16
YUYISHARE 2019-04-23
88487901 2019-04-21