diff --git a/django/forms/fields.py b/django/forms/fields.py index 03455e09890..51551ded479 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -448,6 +448,10 @@ class EmailField(CharField): } default_validators = [validators.validate_email] + def clean(self, value): + value = self.to_python(value).strip() + return super(EmailField, self).clean(value) + class FileField(Field): widget = ClearableFileInput default_error_messages = { diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py index d29e2e8e436..cf0c3f659c7 100644 --- a/tests/regressiontests/forms/fields.py +++ b/tests/regressiontests/forms/fields.py @@ -430,6 +430,7 @@ class FieldsTests(TestCase): self.assertEqual(u'', f.clean('')) self.assertEqual(u'', f.clean(None)) self.assertEqual(u'person@example.com', f.clean('person@example.com')) + self.assertEqual(u'example@example.com', f.clean(' example@example.com \t \t ')) self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo') self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@') self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid e-mail address.']", f.clean, 'foo@bar')