Fixed #9890 -- Modified the regex validation for email addresses to match RFC822/1035. Thanks to ozgur for the report, and kratorius for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10573 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4eaf4155f8
commit
48b459a83e
|
@ -422,7 +422,7 @@ class RegexField(CharField):
|
||||||
email_re = re.compile(
|
email_re = re.compile(
|
||||||
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
|
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
|
||||||
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
|
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
|
||||||
r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
|
r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
|
||||||
|
|
||||||
class EmailField(RegexField):
|
class EmailField(RegexField):
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
|
|
|
@ -745,6 +745,27 @@ ValidationError: [u'Enter a valid e-mail address.']
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValidationError: [u'Enter a valid e-mail address.']
|
ValidationError: [u'Enter a valid e-mail address.']
|
||||||
|
>>> f.clean('example@invalid-.com')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValidationError: [u'Enter a valid e-mail address.']
|
||||||
|
>>> f.clean('example@-invalid.com')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValidationError: [u'Enter a valid e-mail address.']
|
||||||
|
>>> f.clean('example@inv-.alid-.com')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValidationError: [u'Enter a valid e-mail address.']
|
||||||
|
>>> f.clean('example@inv-.-alid.com')
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValidationError: [u'Enter a valid e-mail address.']
|
||||||
|
>>> f.clean('example@valid-----hyphens.com')
|
||||||
|
u'example@valid-----hyphens.com'
|
||||||
|
|
||||||
|
>>> f.clean('example@valid-with-hyphens.com')
|
||||||
|
u'example@valid-with-hyphens.com'
|
||||||
|
|
||||||
>>> f = EmailField(required=False)
|
>>> f = EmailField(required=False)
|
||||||
>>> f.clean('')
|
>>> f.clean('')
|
||||||
|
|
Loading…
Reference in New Issue