Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p><strong>UPDATE 2017</strong>: the code below is 7 years old and was since modified, fixed and expanded. For anyone wishing to do this now, the correct code lives around here: <a href="https://github.com/django/django/blob/master/django/core/validators.py#L168-L180" rel="noreferrer">https://github.com/django/django/blob/master/django/core/validators.py#L168-L180</a></p> </blockquote> <p>Here is part of django.core.validators you may find interesting :)</p> <pre><code>class EmailValidator(RegexValidator): def __call__(self, value): try: super(EmailValidator, self).__call__(value) except ValidationError, e: # Trivial case failed. Try for possible IDN domain-part if value and u'@' in value: parts = value.split(u'@') domain_part = parts[-1] try: parts[-1] = parts[-1].encode('idna') except UnicodeError: raise e super(EmailValidator, self).__call__(u'@'.join(parts)) else: raise email_re = re.compile( r"(^[-!#$%&amp;'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&amp;'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain validate_email = EmailValidator(email_re, _(u'Enter a valid e-mail address.'), 'invalid') </code></pre> <p>so if you don't want to use forms and form fields, you can import <code>email_re</code> and use it in your function, or even better - import <code>validate_email</code> and use it, catching possible <code>ValidationError</code>.</p> <pre><code>def validateEmail( email ): from django.core.validators import validate_email from django.core.exceptions import ValidationError try: validate_email( email ) return True except ValidationError: return False </code></pre> <p>And here is <a href="http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html" rel="noreferrer">Mail::RFC822::Address regexp</a> used in PERL, if you really need to be that paranoid.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload