Skip to content

Commit 376d1c9

Browse files
author
Shaun Duncan
committed
EmailField should honor StringField validation as well
1 parent 7a1b110 commit 376d1c9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mongoengine/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class EmailField(StringField):
141141
def validate(self, value):
142142
if not EmailField.EMAIL_REGEX.match(value):
143143
self.error('Invalid Mail-address: %s' % value)
144+
super(EmailField, self).validate(value)
144145

145146

146147
class IntField(BaseField):

tests/test_fields.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,18 @@ class Post(Document):
21142114
post.comments[1].content = 'here we go'
21152115
post.validate()
21162116

2117+
def test_email_field_honors_regex(self):
2118+
class User(Document):
2119+
email = EmailField(regex=r'\[email protected]')
2120+
2121+
# Fails regex validation
2122+
user = User(email='[email protected]')
2123+
self.assertRaises(ValidationError, user.validate)
2124+
2125+
# Passes regex validation
2126+
user = User(email='[email protected]')
2127+
self.assertTrue(user.validate() is None)
2128+
21172129

21182130
if __name__ == '__main__':
21192131
unittest.main()

0 commit comments

Comments
 (0)