【问题标题】:Cant seem to find how to check for valid emails in App Engine似乎无法找到如何在 App Engine 中检查有效电子邮件
【发布时间】:2010-12-20 06:09:02
【问题描述】:

任何人都知道任何文档可能是关于此的吗? 到目前为止,我只发现了这个

http://code.google.com/appengine/articles/djangoforms.html

EmailProperty() 只验证空字符串... sigh

【问题讨论】:

  • 您面临的问题是什么?如果您只是在寻找文档 - docs.djangoproject.com/en/dev/ref/models/fields/#emailfield
  • 没有相关文档,因为 App Engine 不包含任何电子邮件验证组件。在不向其发送消息的情况下验证电子邮件是否有效并非易事。
  • 我想出了一个解决方案angelmedrano.com/?p=207
  • 啊,您不是要验证电子邮件是否确实有效,您只是想知道字符串中是否包含 @ 符号并且看起来像电子邮件字符串。
  • 彼得,我想你是对的。我将采用任何可以进行某种验证的内置方法。你知道更好的解决方案吗?

标签: python django google-app-engine


【解决方案1】:

以下验证服务器上的电子邮件地址:

from google.appengine.api import mail
if not mail.is_email_valid(to_addr):
  # Return an error message...

希望有帮助吗?

【讨论】:

  • 我想知道这是否是一个较新的功能。几个月前我找不到类似的东西。谢谢!
  • 根本不起作用,mail.is_email_valid('asd') 返回 false。查看源代码,此方法几乎没有作用,但检查字符串是否为空白
  • @pheelicks 我想你的意思是mail.is_email_valid('asd') 返回true
【解决方案2】:

如果您检查 Google 的 mail 函数的来源,您会看到 ma​​il.is_email_valid() 仅检查字符串是否为无/空。

从这个site,我发现了一个符合RFC822 的Python 电子邮件地址验证器。

import re

qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
quoted_pair = '\\x5c[\\x00-\\x7f]'
domain_literal = "\\x5b(?:%s|%s)*\\x5d" % (dtext, quoted_pair)
quoted_string = "\\x22(?:%s|%s)*\\x22" % (qtext, quoted_pair)
domain_ref = atom
sub_domain = "(?:%s|%s)" % (domain_ref, domain_literal)
word = "(?:%s|%s)" % (atom, quoted_string)
domain = "%s(?:\\x2e%s)*" % (sub_domain, sub_domain)
local_part = "%s(?:\\x2e%s)*" % (word, word)
addr_spec = "%s\\x40%s" % (local_part, domain)


email_address = re.compile('\A%s\Z' % addr_spec)
# How this is used: 
def isValidEmailAddress(email):
    if email_address.match(email):
        return True
    else:
        return False

* 如果您使用它,请使用this 版本,因为它包含创建它的人的姓名等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 2018-08-02
    • 2015-12-29
    • 2015-05-29
    • 2018-01-31
    • 2011-10-07
    • 1970-01-01
    相关资源
    最近更新 更多