tailieunhanh - Web to py enterprise web framework - p 23

VALIDATORS 205 IS LENGTH Checks if length of field’s value fits between given boundaries. Works for both text and file inputs. Its arguments are: • maxsize: the maximum allowed length / size • minsize: the minimum allowed length / size Examples: Check if text string is shorter than 33 characters: 1 INPUT(_type='text', _name='name', requires=IS_LENGTH(32)) Check if password string is longer than 5 characters: 1 INPUT(_type='password', _name='name', requires=IS_LENGTH(minsize=6)) Check if uploaded file has size between 1KB and 1MB: 1 INPUT(_type='file', _name='name', requires=IS_LENGTH(1048576, 1024)) For all field types except for files, it checks the length of the value. In the case of files, the value is a , so it validates the length of the. | VALIDATORS 205 ISLENGTH Checks if length of field s value fits between given boundaries. Works for both text and file inputs. Its arguments are maxsize the maximum allowed length size minsize the minimum allowed length size Examples Check if text string is shorter than 33 characters 1 INPUT _type text _name name requires IS_LENGTH 32 Check if password string is longer than 5 characters 1 INPUT _type password _name name requires IS_LENGTH minsize 6 Check if uploaded file has size between 1KB and 1MB 1 INPUT _type file _name name requires IS_LENGTH 1048576 1024 For all field types except for files it checks the length of the value. In the case of files the value is a cookie. Fieldstorage so it validates the length of the data in the file which is the behavior one might intuitively expect. IS_LIST_OF This is not properly a validator. Its intended use is to allow validations of fields that return multiple values. It is used in those rare cases when a form contains multiple fields with the same name or a multiple selection box. Its only argument is another validator and all it does is to apply the other validator to each element of the list. For example the following expression checks that every item in a list is an integer in the range 0-10 1 requires IS_LIST_OF IS_INT_IN_RANGE 0 10 It never returns an error and does not contain an error message. The inner validator controls the error generation. ISLOWER This validator never returns an error. It just converts the value to lower case. 1 requires IS_LOWER ISMATCH This validator matches the value against a regular expression and returns an error if it does not match. Here is an example of usage to validate a US zip code 1 requires IS_MATCH d 5 - d 4 2 error_message not a zip code Here is an example of usage to validate an IPv4 address 1 requires IS_MATCH d 1 3 . d 1 3 3 2 error_message not an IP address 206 FORMS AND VALIDATORS Here is an example of usage to validate a US phone number 1 requires IS_MATCH 1 - d 3 - d 3 d 3

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.