Changeset 6343 for main


Ignore:
Timestamp:
11 Jun 2011, 05:17:28 (14 years ago)
Author:
Henrik Bettermann
Message:

Define validation method for email addresses and use as constraint (copied from Plone Entwicklerhandbuch).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r6341 r6343  
    2323"""
    2424import os
     25import re
    2526import waeup.sirp.browser
    2627
     
    5253    os.path.join(IMAGE_PATH, 'placeholder_f.jpg')).read()
    5354
     55# Define a valiation method for email addresses
     56class NotAnEmailAddress(schema.ValidationError):
     57    __doc__ = u"Invalid email address"
     58
     59check_email = re.compile(r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match
     60def validate_email(value):
     61    if not check_email(value):
     62        raise NotAnEmailAddress(value)
     63    return True
     64
    5465@provider(schema.interfaces.IContextAwareDefaultFactory)
    5566def default_passport_image(context):
     
    336347        title = u'Email',
    337348        required = False,
     349        constraint=validate_email,
    338350        )
    339351    phone = schema.Int(
Note: See TracChangeset for help on using the changeset viewer.