Back to index

plone3  3.1.7
BaseValidators.py
Go to the documentation of this file.
00001 from RegexValidator import RegexValidator
00002 from RangeValidator import RangeValidator
00003 
00004 # protocols for isURL validator, the secure (*s) variants are automagically
00005 # added
00006 protocols = ('http', 'ftp', 'irc', 'news', 'imap', 'gopher', 'jabber',
00007     'webdav', 'smb', 'fish', 'ldap', 'pop3', 'smtp', 'sftp', 'ssh', 'feed'
00008     )
00009 
00010 # email re w/o leading '^'
00011 EMAIL_RE = "([0-9a-zA-Z_&.'+-]+!)*[0-9a-zA-Z_&.'+-]+@(([0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-z-A-Z])?\.)+[a-zA-Z]{2,6}|([0-9]{1,3}\.){3}[0-9]{1,3})$"
00012 
00013 baseValidators = [
00014     RangeValidator('inNumericRange', title='', description=''),
00015     RegexValidator('isDecimal',
00016                    r'^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$',
00017                    title='', description='',
00018                    errmsg='is not a decimal number.'),
00019     RegexValidator('isInt', r'^([+-])?\d+$', title='', description='',
00020                    errmsg='is not an integer.'),
00021     RegexValidator('isPrintable', r'[a-zA-Z0-9\s]+$', title='', description='',
00022                    errmsg='contains unprintable characters'),
00023     RegexValidator('isSSN', r'^\d{9}$', title='', description='',
00024                    errmsg='is not a well formed SSN.'),
00025     RegexValidator('isUSPhoneNumber', r'^\d{10}$', ignore='[\(\)\-\s]',
00026                    title='', description='',
00027                    errmsg='is not a valid us phone number.'),
00028     RegexValidator('isInternationalPhoneNumber', r'^\d+$', ignore='[\(\)\-\s\+]',
00029                    title='', description='',
00030                    errmsg='is not a valid international phone number.'),
00031     RegexValidator('isZipCode', r'^(\d{5}|\d{9})$',
00032                    title='', description='',
00033                    errmsg='is not a valid zip code.'),
00034     RegexValidator('isURL', r'(%s)s?://[^\s\r\n]+' % '|'.join(protocols),
00035                    title='', description='',
00036                    errmsg='is not a valid url.'),
00037     RegexValidator('isEmail', '^'+EMAIL_RE,
00038                    title='', description='',
00039                    errmsg='is not a valid email address.'),
00040     RegexValidator('isMailto', '^mailto:'+EMAIL_RE,
00041                    title='', description='',
00042                    errmsg='is not a valid email address.'),
00043     RegexValidator('isUnixLikeName', r"^[A-Za-z][\w\d\-\_]{0,7}$",
00044                    title="", description="",
00045                    errmsg="this name is not a valid identifier"),
00046     ]
00047 
00048 __all__ = ('baseValidators', )