summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-11-06 22:59:18 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-11-06 22:59:18 +0000
commita218cf57988e2b6bea59734ea84ddf8a59df14f1 (patch)
tree1ce9d14c8a158e86a826ae9d37698049764725db
parent911a6dfe04df57a1f33b533eb71e9624f1ed5f14 (diff)
Fixed #281 -- Made e-mail address validation much more strict and accurate.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1106 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/core/validators.py3
-rw-r--r--docs/model-api.txt2
2 files changed, 3 insertions, 2 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index 5260fe6b8b..bdcce990f8 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -17,7 +17,8 @@ alnumurl_re = re.compile(r'^[\w/]+$')
ansi_date_re = re.compile('^%s$' % _datere)
ansi_time_re = re.compile('^%s$' % _timere)
ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
-email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
+# From http://www.twilightsoul.com/Default.aspx?tabid=134
+email_re = re.compile(r'^((([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+[\t\x20]*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")+)?[\t\x20]*<([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+(\.[!#-\'\*\+\-/-9=\?A-Z\^-~]+)*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")@(([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,}|\[(([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\])>[\t\x20]*|([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+(\.[!#-\'\*\+\-/-9=\?A-Z\^-~]+)*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")@(([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,}|\[(([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\]))$')
integer_re = re.compile(r'^-?\d+$')
ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$')
phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
diff --git a/docs/model-api.txt b/docs/model-api.txt
index b27a298d8e..9922072b8a 100644
--- a/docs/model-api.txt
+++ b/docs/model-api.txt
@@ -244,7 +244,7 @@ Here are all available field types:
``EmailField``
A ``CharField`` that checks that the value is a valid e-mail address.
- (Currently, this is a loose test.) This doesn't accept ``maxlength``.
+ This doesn't accept ``maxlength``.
``FileField``
A file-upload field.