开发者

Cant seem to find how to check for valid emails in App Engine

开发者 https://www.devze.com 2023-01-31 04:44 出处:网络
any one know where any docs might be about this? So far I\'ve only found this http://code.google.com/app开发者_如何学Cengine/articles/djangoforms.html

any one know where any docs might be about this? So far I've only found this

http://code.google.com/app开发者_如何学Cengine/articles/djangoforms.html

EmailProperty() only validates for empty strings... sigh


The following validates the email address on the server:

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

Hope that helps?


If you check the source for Google's mail function you'll see that mail.is_email_valid() only checks that the string is not None/empty.

From this site I found an RFC822 compliant Python email address validator.

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

* If you use this please use this version as it contains the name and so on of the person whom created it.

0

精彩评论

暂无评论...
验证码 换一张
取 消