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
|
Rev | Line | |
---|
[0] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 |
|
---|
[11] | 3 | """
|
---|
[16] | 4 | The mailjam project - tools.py
|
---|
[11] | 5 |
|
---|
| 6 | This file is released under the BSD license, see LICENSE for
|
---|
| 7 | more information.
|
---|
| 8 |
|
---|
| 9 | Francisco de Borja Lopez Rio - <borja@codigo23.net>
|
---|
| 10 | Soluciones Informaticas Codigo23 S.L.U. - http://codigo23.net
|
---|
| 11 | """
|
---|
| 12 |
|
---|
[0] | 13 | import re
|
---|
| 14 |
|
---|
| 15 | def 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 |
|
---|
[22] | 27 | if not isinstance(address, str) and not isinstance(address, unicode):
|
---|
[1] | 28 | return False
|
---|
| 29 |
|
---|
[0] | 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.