有效的电子邮件功能。elif语句

2024-09-28 22:25:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有我的功能设置,我只是不知道如何写一个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"))

Tags: comfalseindexreturnaddressdefcountme