source: mailjam/mailjam/tools.py@ 22:55bdffd989da

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

Fixed a bug in the email address validator (email address should be valid
as unicode objects too, and not only as string objects)

File size: 1.0 KB
Line 
1# -*- coding: utf-8 -*-
2
3"""
4The mailjam project - tools.py
5
6This file is released under the BSD license, see LICENSE for
7more information.
8
9Francisco de Borja Lopez Rio - <borja@codigo23.net>
10Soluciones Informaticas Codigo23 S.L.U. - http://codigo23.net
11"""
12
13import re
14
15def validate_email_address(address):
16
17 """
18 This function validates a given address, returning True
19 if it is a valid address, False otherwise.
20
21 The function uses a regexp from the django project, and
22 it is inspired in this snippet:
23
24 http://djangosnippets.org/snippets/1093/
25 """
26
27 if not isinstance(address, str) and not isinstance(address, unicode):
28 return False
29
30 email_re = re.compile(
31 r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
32 r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
33 r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain
34 return True if email_re.match(address) else False
Note: See TracBrowser for help on using the repository browser.