Limiting the number of values that could be input in a form field

19 views
Skip to first unread message

mostwanted

unread,
Dec 8, 2021, 2:23:01 PM12/8/21
to web2py-users
Is there a validator that could be used to limit the number of values that could be submitted in a form field? I want users to input their ID numbers but they cant be more than 9 characters, how do i achieve this?

Clemens

unread,
Dec 8, 2021, 2:35:17 PM12/8/21
to web2py-users
I didn't test it, but this should do the job:
requires = IS_MATCH('^\w{1,9}$', error_message='must be 1 to 9 characters/digits')

For further information about validators with regular expressions have a look here:

Clemens

unread,
Dec 8, 2021, 2:41:45 PM12/8/21
to web2py-users
The right link to the chapter in the web2py documentation is:
http://web2py.com/books/default/chapter/29/07/forms-and-validators#IS_MATCH

mostwanted

unread,
Dec 9, 2021, 12:38:14 AM12/9/21
to web2py-users
Thanks Clemens this worked:
            Field('id_number', requires = IS_MATCH('^\d{9}?$', error_message='An ID Number should have exactly 9 digits')),
Reply all
Reply to author
Forward
0 new messages