forked from web2py/web2py-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2267,14 +2267,35 @@ On success, the ``__call__`` method reads a date string from the form and conver | |
01/01/2008 | ||
``:code | ||
|
||
When multiple validators are required (and stored in a list), they are executed in order and the output of one is passed as input to the next. The chain breaks when one of the validators fails. | ||
#### Multiple Validators | ||
|
||
Normally, when multiple validators are required (and stored in a list), they are executed in order and the output of one is passed as input to the next. The chain breaks when one of the validators fails. | ||
|
||
Conversely, when we call the ``formatter`` method of a field, the formatters of the associated validators are also chained, but in reverse order. | ||
|
||
------ | ||
Notice that as alternative to custom validators, you can also use the ``onvalidate`` argument of ``form.accepts(...)``, ``form.process(...)`` and ``form.validate(...)``. | ||
------ | ||
|
||
As an alternative to the chained behavior described above, | ||
the | ||
``ANY_OF``:inxx validator can be used to combine a list of validators, | ||
and to pass if **any** of the validators pass. | ||
If none of the validators pass, | ||
the error message returned will be that of the last validator in the | ||
list. | ||
|
||
`` | ||
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('[email protected]') | ||
('[email protected]', None) | ||
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('abco') | ||
('abco', None) | ||
>>> ANY_OF([IS_EMAIL(),IS_ALPHANUMERIC()])('@ab.co') | ||
('@ab.co', 'enter only letters, numbers, and underscore') | ||
>>> ANY_OF([IS_ALPHANUMERIC(),IS_EMAIL()])('@ab.co') | ||
('@ab.co', 'enter a valid email address') | ||
``:code | ||
|
||
|
||
#### Validators with dependencies | ||
|
||
|