Package web2py :: Package gluon :: Module validators :: Class Validator
[hide private]
[frames] | no frames]

Class Validator

source code

object --+
         |
        Validator
Known Subclasses:
CLEANUP, IS_MATCH, IS_DATE, IS_DATETIME, IS_DECIMAL_IN_RANGE, IS_EMAIL, IS_EMPTY_OR, IS_EQUAL_TO, IS_EXPR, IS_FLOAT_IN_RANGE, IS_IMAGE, IS_INT_IN_RANGE, IS_IN_DB, IS_IN_SET, IS_IPV4, IS_LENGTH, IS_LIST_OF, IS_LOWER, IS_NOT_EMPTY, IS_NOT_IN_DB, IS_SLUG, IS_TIME, IS_UPLOAD_FILENAME, IS_UPPER, IS_URL, IS_GENERIC_URL, IS_HTTP_URL

Root for all validators, mainly for documentation purposes.

Validators are classes used to validate input fields (including forms generated from database tables).

Here is an example of using a validator with a FORM:
   INPUT(_name='a', requires=IS_INT_IN_RANGE(0, 10))
Here is an example of how to require a validator for a table field:
   db.define_table('person', SQLField('name'))
   db.person.name.requires=IS_NOT_EMPTY()
Validators are always assigned using the requires attribute of a field. A field can have a single validator or multiple validators. Multiple validators are made part of a list:
   db.person.name.requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'person.id')]

Validators are called by the function accepts on a FORM or other HTML helper object that contains a form. They are always called in the order in which they are listed.

Built-in validators have constructors that take the optional argument error message which allows you to change the default error message. Here is an example of a validator on a database table:
   db.person.name.requires=IS_NOT_EMPTY(error_message=T('fill this'))

where we have used the translation operator T to allow for internationalization.

Notice that default error messages are not translated.

Instance Methods [hide private]
 
formatter(self, value)
For some validators returns a formatted version (matching the validator) of value.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

formatter(self, value)

source code 
For some validators returns a formatted version (matching the validator) of value. Otherwise just returns the value.