Ticket #9890: emailfield-r9692.diff

File emailfield-r9692.diff, 1.6 KB (added by Ivan Giuliani, 16 years ago)

patch + tests

  • django/forms/fields.py

     
    421421email_re = re.compile(
    422422    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
    423423    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
    424     r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE)  # domain
     424    r')@(?:[A-Z0-9]+(?:-[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE)  # domain
    425425
    426426class EmailField(RegexField):
    427427    default_error_messages = {
  • tests/regressiontests/forms/fields.py

     
    745745Traceback (most recent call last):
    746746...
    747747ValidationError: [u'Enter a valid e-mail address.']
     748>>> f.clean('example@invalid-.com')
     749Traceback (most recent call last):
     750...
     751ValidationError: [u'Enter a valid e-mail address.']
     752>>> f.clean('example@inv-.alid-.com')
     753Traceback (most recent call last):
     754...
     755ValidationError: [u'Enter a valid e-mail address.']
     756>>> f.clean('example@inv-.-alid.com')
     757Traceback (most recent call last):
     758...
     759ValidationError: [u'Enter a valid e-mail address.']
     760>>> f.clean('example@inv-----alid.com')
     761Traceback (most recent call last):
     762...
     763ValidationError: [u'Enter a valid e-mail address.']
     764>>> f.clean('example@valid-with-hyphens.com')
     765u'example@valid-with-hyphens.com'
    748766
    749767>>> f = EmailField(required=False)
    750768>>> f.clean('')
Back to Top