|
Last change
on this file since 11:078c7b030cee was 11:078c7b030cee, checked in by Borja Lopez <borja@…>, 13 years ago |
|
Removed legacy configs from the config module
Added some headers to the sources (setting author, email, website
and references to the LICENSE)
|
|
File size:
993 bytes
|
| Line | |
|---|
| 1 | # -*- coding: utf-8 -*-
|
|---|
| 2 |
|
|---|
| 3 | """
|
|---|
| 4 | The postman project - tools.py
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 27 | if not isinstance(address, str):
|
|---|
| 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.