Email

Validate an email address.

If you pass resolve_domain=True, then it will try to resolve the domain name to make sure it's valid. This takes longer, of course. You must have the pyDNS modules installed to look up DNS (MX and A) records.

>>> e = Email()
>>> e.to_python(' test@foo.com ')
'test@foo.com'
>>> e.to_python('test')
Traceback (most recent call last):
    ...
Invalid: An email address must contain a single @
>>> e.to_python('test@foobar.com.5')
Traceback (most recent call last):
    ...
Invalid: The domain portion of the email address is invalid (the portion after the @: foobar.com.5)
>>> e.to_python('o*reilly@test.com')
'o*reilly@test.com'
>>> e = Email(resolve_domain=True)
>>> e.resolve_domain
True
>>> e.to_python('doesnotexist@colorstudy.com')
'doesnotexist@colorstudy.com'
>>> e.to_python('test@forums.nyu.edu')
'test@forums.nyu.edu'
>>> # NOTE: If you do not have PyDNS installed this example won't work:
>>> e.to_python('test@thisdomaindoesnotexistithinkforsure.com')
Traceback (most recent call last):
    ...
Invalid: The domain of the email address does not exist (the portion after the @: thisdomaindoesnotexistithinkforsure.com)
>>> e = Email(not_empty=False)
>>> e.to_python('')

Messages

badDomain:
The domain portion of the email address is invalid (the portion after the @: %(domain)s)
badType:
The input must be a string (not a %(type)s: %(value)r)
badUsername:
The username portion of the email address is invalid (the portion before the @: %(username)s)
domainDoesNotExist:
The domain of the email address does not exist (the portion after the @: %(domain)s)
empty:
Please enter an email address
noAt:
An email address must contain a single @
noneType:
The input must be a string (not None)
socketError:
An error occured when trying to connect to the server: %(error)s

Attributes

a gettextargs

{}

a domainRE

<_sre.SRE_Pattern object at 0xb778a5c0>

a strip

False

a use_builtins_gettext

True

a accept_python

True

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a declarative_count

30

a __unpackargs__

()

a usernameRE

<_sre.SRE_Pattern object at 0xb77ebf20>

a compound

False

a not_empty

False

a resolve_domain

False

a __mutableattributes__

()

a repeating

False

Methods

f __initargs__(self, new_attrs) ...

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __sourcerepr__(self, source, binding=None) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __init__(self, *args, **kw) ...

f validate_python(self, value, state) ...

See the source for more information.