我有我的功能设置,我只是不知道如何写一个elif语句,检查电子邮件是否只有一个域,如果它是一个有效的域。你知道吗
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"))
要获取电子邮件的域,请使用rsplit:
要检查域列表中是否有域,可以执行以下操作:
相关问题 更多 >
编程相关推荐