Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve email address validator regex & add tests re: #82.

  • Loading branch information...
commit 94aedda8553008cc692f8444482cf7977ef51508 1 parent 4a1776e
@douglatornell douglatornell authored
Showing with 5 additions and 2 deletions.
  1. +3 −2 colander/__init__.py
  2. +2 −0  colander/tests/test_colander.py
View
5 colander/__init__.py
@@ -272,10 +272,11 @@ class Email(Regex):
otherwise, defaults to 'Invalid email address'.
"""
def __init__(self, msg=None):
+ email_regex = text_(
+ '(?i)^[A-Z0-9._%+-]+@[A-Z0-9]+([.-][A-Z0-9]+)*\.[A-Z]{2,4}$')
if msg is None:
msg = _("Invalid email address")
- super(Email, self).__init__(
- text_('(?i)^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'), msg=msg)
+ super(Email, self).__init__(email_regex, msg=msg)
class Range(object):
""" Validator which succeeds if the value it is passed is greater
View
2  colander/tests/test_colander.py
@@ -362,6 +362,8 @@ def test_invalid_emails(self):
self.assertRaises(Invalid, validator, None, 'name@here.comcom')
self.assertRaises(Invalid, validator, None, '@here.us')
self.assertRaises(Invalid, validator, None, '(name)@here.info')
+ self.assertRaises(Invalid, validator, None, 'me@here..com')
+ self.assertRaises(Invalid, validator, None, 'me@we-here-.com')
class TestLength(unittest.TestCase):
def _makeOne(self, min=None, max=None):
Please sign in to comment.
Something went wrong with that request. Please try again.