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

Class IS_LENGTH

source code

object --+    
         |    
 Validator --+
             |
            IS_LENGTH

Checks if length of field's value fits between given boundaries. Works for both text and file inputs.

Arguments:

maxsize: maximum allowed length / size minsize: minimum allowed length / size

Examples:
   #Check if text string is shorter than 33 characters:
   INPUT(_type='text', _name='name', requires=IS_LENGTH(32))

   #Check if password string is longer than 5 characters:
   INPUT(_type='password', _name='name', requires=IS_LENGTH(minsize=6))

   #Check if uploaded file has size between 1KB and 1MB:
   INPUT(_type='file', _name='name', requires=IS_LENGTH(1048576, 1024))

   >>> IS_LENGTH()('')
   ('', None)
   >>> IS_LENGTH()('1234567890')
   ('1234567890', None)
   >>> IS_LENGTH(maxsize=5, minsize=0)('1234567890')  # too long
   ('1234567890', 'enter from 0 to 5 characters')
   >>> IS_LENGTH(maxsize=50, minsize=20)('1234567890')  # too short
   ('1234567890', 'enter from 20 to 50 characters')


Instance Methods [hide private]
 
__init__(self, maxsize=255, minsize=0, error_message='enter from %(min)g to %(max)g characters')
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__call__(self, value) source code

Inherited from Validator: formatter

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, maxsize=255, minsize=0, error_message='enter from %(min)g to %(max)g characters')
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)