Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Dec 10, 2012
2 parents 452cd12 + 376d1c9 commit 155d79f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions mongoengine/fields.py
Expand Up @@ -149,6 +149,7 @@ class EmailField(StringField):
def validate(self, value):
if not EmailField.EMAIL_REGEX.match(value):
self.error('Invalid Mail-address: %s' % value)
super(EmailField, self).validate(value)


class IntField(BaseField):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_fields.py
Expand Up @@ -2299,6 +2299,18 @@ class Post(Document):
post.comments[1].content = 'here we go'
post.validate()

def test_email_field_honors_regex(self):
class User(Document):
email = EmailField(regex=r'\w+@example.com')

# Fails regex validation
user = User(email='me@foo.com')
self.assertRaises(ValidationError, user.validate)

# Passes regex validation
user = User(email='me@example.com')
self.assertTrue(user.validate() is None)


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

0 comments on commit 155d79f

Please sign in to comment.