You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/options/special_validator.rst
+94-5Lines changed: 94 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
Special Validator
2
2
=================
3
3
4
-
Special validators are validators that are used to combine or mutate the normal validators.
5
-
They are used to create complex validation logic by combining multiple validators or inverting the result of a validator.
6
-
7
4
Overview
8
5
--------
9
6
7
+
Special validators are validators that are used to combine or mutate the normal validators.
8
+
They are used to create complex validation logic by combining multiple validators or inverting the result of a validator.
10
9
11
10
Example
12
-
11
+
-------
13
12
14
13
.. code-block:: python
15
14
@@ -29,14 +28,43 @@ Available Special Validators
29
28
The following special validators are available:
30
29
31
30
- `AndValidator`_
32
-
- `IfValidator`_
33
31
- `NotValidator`_
34
32
- `OrValidator`_
35
33
- `XorValidator`_
36
34
37
35
Detailed Description
38
36
--------------------
39
37
38
+
AndValidator
39
+
~~~~~~~~~~~~
40
+
41
+
**Description:**
42
+
43
+
Validates that the input passes all of the provided validators. This composite validator performs a logical AND over its constituent validators.
44
+
45
+
**Parameters:**
46
+
47
+
- **validators** (*List[BaseValidator]*): A list of validators that must all pass.
48
+
- **error_message** (*Optional[str]*): Custom error message if any of the validators fail.
49
+
50
+
**Expected Behavior:**
51
+
52
+
The validator sequentially applies each validator in the provided list to the input value. If any validator raises a ``ValidationError``, the AndValidator immediately raises a ``ValidationError``. If all validators pass, the input is considered valid.
53
+
54
+
**Example Usage:**
55
+
56
+
.. code-block:: python
57
+
58
+
from flask_inputfilter import InputFilter
59
+
from flask_inputfilter.Validator import AndValidator, IsIntegerValidator, RangeValidator
@@ -65,3 +93,64 @@ Executes the inner validator on the input. If the inner validator does not raise
65
93
self.add('value', validators=[
66
94
NotValidator(validator=IsIntegerValidator())
67
95
])
96
+
97
+
OrValidator
98
+
~~~~~~~~~~~
99
+
100
+
**Description:**
101
+
102
+
Validates that the input passes at least one of the provided validators. This composite validator performs a logical OR over its constituent validators.
103
+
104
+
**Parameters:**
105
+
106
+
- **validators** (*List[BaseValidator]*): A list of validators to apply.
107
+
- **error_message** (*Optional[str]*): Custom error message if none of the validators pass.
108
+
109
+
**Expected Behavior:**
110
+
111
+
The validator applies each validator in the provided list to the input value. If any one validator passes without raising a ``ValidationError``, the validation is considered successful. If all validators fail, it raises a ``ValidationError`` with the provided error message or a default message.
112
+
113
+
**Example Usage:**
114
+
115
+
.. code-block:: python
116
+
117
+
from flask_inputfilter import InputFilter
118
+
from flask_inputfilter.Validator import OrValidator, IsIntegerValidator, IsStringValidator
Validates that the input passes exactly one of the provided validators. This composite validator ensures that the input does not pass zero or more than one of the specified validators.
133
+
134
+
**Parameters:**
135
+
136
+
- **validators** (*List[BaseValidator]*): A list of validators, of which exactly one must pass.
137
+
- **error_message** (*Optional[str]*): Custom error message if the input does not satisfy exactly one validator.
138
+
139
+
**Expected Behavior:**
140
+
141
+
The validator applies each validator in the provided list to the input value and counts the number of validators that pass without raising a ``ValidationError``. If exactly one validator passes, the input is considered valid; otherwise, a ``ValidationError`` is raised with the provided or default error message.
142
+
143
+
**Example Usage:**
144
+
145
+
.. code-block:: python
146
+
147
+
from flask_inputfilter import InputFilter
148
+
from flask_inputfilter.Validator import XorValidator, IsIntegerValidator, IsStringValidator
0 commit comments