class ANY(object):
def __init__(self, validators):
self.validators = validators
def __call__(self, value):
# validates the value against each validator
results = [validator(value) for validator in self.validators]
# Check if there is an invalid result
for result in results:
if result[1]:
# if invalid value found returns it.
return result
#else returns the value and None, which means "valid"
return (value, None)
db.table.somefield.requires = ANY([IS_EMAIL(), IS_MATCH(), IS_NOT_EMPTY()])
it is a great idea to include ANY and ALL metavalidators to
gluon.validators.
On Thu, Feb 14, 2013 at 11:55 PM, Alec Taylor <[email protected]>wrote:
> I am writing in a signup form for users of my site.
>
> To signup, they can either use their email address `IS_EMAIL()`; or an
> outside uid (covered by an `IS_MATCH()`).
>
> (it's a 1 field form)
>
> One solution to validating the form is to just check the vars in the
> controller, and have two Fields in the Table; one for email, the other
> for this outside uid.
>
> Is there another solution; utilising multiple validators in the
> requires, much like `IS_NONE_OR()` validator?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
> --
>
> ---
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.