[Zope3-Users] schema constraint sets required?

Adam Groszer adamg at fw.hu
Mon Aug 22 08:58:59 EDT 2005


I'd like to check a field if it is a valid e-mail address.
It can be also empty.

The first trial was:
class ISzemely(Interface):
...
    email = TextLine(
        title=u"Email cim",
        description=u"Email cim",
        constraint=re.compile("(^[\w\W]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$)|(^$)").match
        )
...

The second was:
EMAIL_REGEX = re.compile("(^[\w\W]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$)|(^$)")

def emailcheck(value):
    if value is None:
        return True
    return EMAIL_REGEX.match(value)

class ISzemely(Interface):
...
    email = TextLine(
        title=u"Email cim",
        description=u"Email cim",
        constraint=emailcheck
        )
...

If I do not fill in a value in the browser "Required input is
missing." message comes.
At the second version the execution even does not reach "emailcheck".

How to solve that?

-- 
Best regards,
 Adam                          mailto:adamg at fw.hu




More information about the Zope3-users mailing list