Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #281 -- Made e-mail address validation much more strict and acc…

…urate.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1106 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a218cf57988e2b6bea59734ea84ddf8a59df14f1 1 parent 911a6df
Adrian Holovaty authored November 06, 2005
3  django/core/validators.py
@@ -17,7 +17,8 @@
17 17
 ansi_date_re = re.compile('^%s$' % _datere)
18 18
 ansi_time_re = re.compile('^%s$' % _timere)
19 19
 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
20  
-email_re = re.compile(r'^[-\w.+]+@\w[\w.-]+$')
  20
+# From http://www.twilightsoul.com/Default.aspx?tabid=134
  21
+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])\]))$')
21 22
 integer_re = re.compile(r'^-?\d+$')
22 23
 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}$')
23 24
 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE)
2  docs/model-api.txt
@@ -244,7 +244,7 @@ Here are all available field types:
244 244
 
245 245
 ``EmailField``
246 246
     A ``CharField`` that checks that the value is a valid e-mail address.
247  
-    (Currently, this is a loose test.) This doesn't accept ``maxlength``.
  247
+    This doesn't accept ``maxlength``.
248 248
 
249 249
 ``FileField``
250 250
     A file-upload field.

0 notes on commit a218cf5

Please sign in to comment.
Something went wrong with that request. Please try again.