【问题标题】:How can I validate an email address in Python without using regular expression? [duplicate]如何在不使用正则表达式的情况下在 Python 中验证电子邮件地址? [复制]
【发布时间】:2021-04-11 16:35:49
【问题描述】:

这就是我所拥有的。但是,当我尝试传递有效的电子邮件(例如 asm@aol.net)时,它不起作用。请帮忙。

 email = email.strip().lower()
        if not "@" in email:
            print("Invalid email")
            print()
            return
        elif not (".com" or ".org" or ".edu" or ".gov" or ".net") in email[-4:]:
            print("Invalid email")
            print()
            return

【问题讨论】:

    标签: python validation email


    【解决方案1】:

    只是修改

    elif not (".com" or ".org" or ".edu" or ".gov" or ".net") in email[-4:]:
    

    elif not email[-4:] in ".com.org.edu.gov.net":
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 2016-11-15
      • 2015-08-24
      • 1970-01-01
      • 2014-03-02
      相关资源
      最近更新 更多