Python 有效的电子邮件功能。elif语句
我已经设置了我的函数,我只是不知道如何编写一个elif语句来检查电子邮件是否只有一个域以及它是否是一个有效域Python 有效的电子邮件功能。elif语句,python,Python,我已经设置了我的函数,我只是不知道如何编写一个elif语句来检查电子邮件是否只有一个域以及它是否是一个有效域 def validEmail(address, domains=(".com ", ".net ", ".org ", ".biz ", ".gov ", ".edu ", ".mil ")): atLocation = address.index("@") atCount = address.count("@") len(address) periodC
def validEmail(address, domains=(".com ", ".net ", ".org ", ".biz ", ".gov ", ".edu ", ".mil ")):
atLocation = address.index("@")
atCount = address.count("@")
len(address)
periodCount = address.count(".")
periodLocation = address.index(".")
if atLocation <= 0:
return False
elif periodCount <= 0:
return False
elif atCount <= 0:
return False
elif periodLocation ==-1:
return False
else:
return True
print(validEmail("me@hotmail.com"))
print(validEmail("@abc.com"))
print(validEmail("me@abc.fat"))
print(validEmail("me@abc."))
print(validEmail("me@abc.def.com"))
def validEmail(地址,域=(“.com”、“.net”、“.org”、“.biz”、“.gov”、“.edu”、“.mil”):
atLocation=地址索引(“@”)
atCount=地址。计数(“@”)
莱恩(地址)
periodCount=地址。计数(“.”)
periodLocation=地址索引(“.”)
如果atLocation要获取电子邮件的域,请使用rsplit:
a_domain = address.rsplit('.', 1)[1]
要检查某个域是否在域列表中,可以执行以下操作:
valid_domian = a_domain in domains
这是一个练习/个人挑战/任务还是你正在做的事情?如果是前者,请继续。如果是后者,你应该使用图书馆。这个轮子已经发明了!