Oops. I overlooked that this is a list field. I changed the IS_LIST_OF in 
trunk and now you can do:

db. 
register.sample_name.requires=IS_LIST_OF((IS_ALPHANUMERIC(),IS_LENGTH(maxsize=6)))

On Wednesday, 8 January 2014 12:48:24 UTC-6, Anthony wrote:
>
> For a list:-type field, I think you can only use IS_IN_SET(..., 
> multiple=True), IS_IN_DB(..., multiple=True), IS_NOT_EMPTY(), and 
> IS_LIST_OF(), no?
>
> IS_LIST_OF() takes only a single additional validator, so to apply 
> multiple validators using it, you would probably have to create a custom 
> validator that applies multiple validators.
>
> Anthony
>
> On Wednesday, January 8, 2014 1:04:36 PM UTC-5, Massimo Di Pierro wrote:
>>
>> You simply need in the model or in the action before SQLFORM
>>
>> db. register.sample_name.requires=(IS_ALPHANUMERIC(),IS_LENGTH(maxsize=6))
>>
>>
>>
>> On Wednesday, 8 January 2014 07:44:15 UTC-6, curly wrote:
>>>
>>> Hello,
>>>
>>> I'm trying to validate a list:string field with is_alphanumeric and 
>>> is_length - trying to ensure that names are no longer than 6 alphanumeric 
>>> characters in length. (I'm running web2py 2.8.1 in ubuntu 12.04)
>>>
>>> view:
>>>     <li>Sample name *: {{=form.custom.widget.sample_name}}</li>
>>>
>>> controller:
>>>     form = SQLFORM(db.register,fields=[..,'sample_name',...])
>>>
>>>     if form.validate(onvalidation=validate_sample_name):
>>>         form.vars.id = db.register.insert(**dict(form.vars))
>>>         response.flash = 'Reg saved.'
>>>         redirect(URL('samples', 'default', 'index'))
>>>     elif form.errors:
>>>         response.flash = 'form has errors'          
>>>     return dict(form=form)
>>>     
>>> model:
>>> db.define_table(
>>>     "register",
>>>     .....
>>>     Field('sample_name','list:string'),
>>> )
>>>
>>> def validate_sample_name(form):
>>>     for sample in form.vars.sample_name:
>>>         out,ers = IS_ALPHANUMERIC()(sample) and 
>>> IS_LENGTH(maxsize=6)('sample')
>>>         if ers:
>>>             form.errors.sample_name = ers
>>>
>>>
>>> The above does check for alphanumeric characters but doesn't seem to 
>>> check for the length of each sample name.
>>>
>>> Am I doing something wrong?
>>>
>>> Many thanks.
>>>
>>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to