--- a/src/pyams_utils/schema.py Thu Sep 21 12:43:22 2017 +0200
+++ b/src/pyams_utils/schema.py Fri Oct 13 09:55:57 2017 +0200
@@ -177,10 +177,15 @@
EMAIL_REGEX = re.compile("^[^ @]+@[^ @]+\.[^ @]+$")
+class InvalidEmail(ValidationError):
+ __doc__ = _("Email address must be entered as « name@domain.name », without '<' and '>' characters")
+
+
@implementer(IMailAddressField)
class MailAddressField(TextLine):
"""Mail address field"""
- def __init__(self, *args, **kwargs):
- kwargs['constraint'] = EMAIL_REGEX.match
- super(MailAddressField, self).__init__(*args, **kwargs)
+ def _validate(self, value):
+ super(MailAddressField, self)._validate(value)
+ if not EMAIL_REGEX.match(value):
+ raise InvalidEmail(value)