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_JSON
- , 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
- , ANY_OF
- , IS_GENERIC_URL
- , IS_HTTP_URL
- , IS_IPADDRESS
- , IS_IPV6
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.
|
formatter(self,
value)
For some validators returns a formatted version (matching the
validator) of value. |
source code
|
|
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__init__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
For some validators returns a formatted version (matching the
validator) of value. Otherwise just returns the value.
|