source: mailjam/src/tools.py@ 0:cce367beda90

Last change on this file since 0:cce367beda90 was 0:cce367beda90, checked in by Borja Lopez <borja@…>, 12 years ago

Initial commit for this project

File size: 699 bytes
Line 
1# -*- coding: utf-8 -*-
2
3import re
4
5def validate_email_address(address):
6
7 """
8 This function validates a given address, returning True
9 if it is a valid address, False otherwise.
10
11 The function uses a regexp from the django project, and
12 it is inspired in this snippet:
13
14 http://djangosnippets.org/snippets/1093/
15 """
16
17 email_re = re.compile(
18 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
19 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
20 r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain
21 return True if email_re.match(address) else False
Note: See TracBrowser for help on using the repository browser.