Changeset 7850 for main/waeup.kofa


Ignore:
Timestamp:
12 Mar 2012, 16:36:38 (13 years ago)
Author:
uli
Message:

Add validator for phone numbers.

File:
1 edited

Legend:

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

    r7843 r7850  
    101101        return grades_dict[value][1]
    102102
    103 # Define a valiation method for email addresses
     103# Define a validation method for email addresses
    104104class NotAnEmailAddress(schema.ValidationError):
    105105    __doc__ = u"Invalid email address"
     
    111111    if not check_email(value):
    112112        raise NotAnEmailAddress(value)
     113    return True
     114
     115# Define a validation method for international phone numbers
     116class InvalidPhoneNumber(schema.ValidationError):
     117    __doc__ = u"Invalid phone number"
     118
     119# represent format +NNN-NNNN-NNNN
     120RE_INT_PHONE = re.compile(r"^\+?\d+\-\d+\-[\d\-]+$")
     121
     122def validate_phone(value):
     123    if RE_INT_PHONE.match(value):
     124        raise InvalidPhoneNumber(value)
    113125    return True
    114126
Note: See TracChangeset for help on using the changeset viewer.