Skip to content

Commit

Permalink
updated checkEmailAddress to not be dependend on CMFDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
agitator committed Mar 1, 2017
1 parent 42623cb commit 9337238
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/collective/contact/core/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,39 @@
from plone.app.textfield import RichText
from plone.app.dexterity.browser.types import TypeSchemaContext

from Products.CMFDefault.utils import checkEmailAddress
from Products.CMFDefault.exceptions import EmailAddressInvalid
# from Products.CMFDefault.utils import checkEmailAddress
# from Products.CMFDefault.exceptions import EmailAddressInvalid

from collective.contact.core import _
from collective.contact.core.interfaces import IContactable
from collective.contact.widget.schema import ContactChoice, ContactList
from collective.contact.widget.source import ContactSourceBinder

# Taken from http://www.regular-expressions.info/email.html
_isemail = r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}"
_isemail = re.compile(_isemail).match


class InvalidEmailAddress(schema.ValidationError):
"""Exception for invalid address"""
__doc__ = _(u"Invalid email address")


def validateEmail(value):
"""Simple email validator"""
try:
checkEmailAddress(value)
except EmailAddressInvalid:
raise InvalidEmailAddress(value)
return True
# def validateEmail(value):
# super(Email, self)._validate(value)
# if _isemail(value):
# return

# raise InvalidEmail(value)


# def validateEmail(value):
# """Simple email validator"""
# try:
# checkEmailAddress(value)
# except EmailAddressInvalid:
# raise InvalidEmailAddress(value)
# return True


class InvalidPhone(schema.ValidationError):
Expand Down Expand Up @@ -142,7 +154,7 @@ class IContactDetails(model.Schema):

email = schema.TextLine(
title=_(u"Email"),
constraint=validateEmail,
# constraint=validateEmail,
required=False,
)

Expand Down

0 comments on commit 9337238

Please sign in to comment.