Skip to content

Commit 01a2589

Browse files
committed
docs: add docs
1 parent 368ab7f commit 01a2589

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

user_guide_src/source/libraries/validation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ You must set the error message for the closure rule.
646646
When you specify the error message, set the array key for the closure rule.
647647
In the above code, the ``required`` rule has the key ``0``, and the closure has ``1``.
648648

649+
Or you can use the following parameters:
650+
651+
.. literalinclude:: validation/041.php
652+
649653
Available Rules
650654
***************
651655

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$validation->setRules(
4+
[
5+
'foo' => [
6+
'required',
7+
static function ($value, $data, &$error, $field) {
8+
if ((int) $value % 2 === 0) {
9+
return true;
10+
}
11+
12+
$error = 'The value is not even.';
13+
14+
return false;
15+
},
16+
],
17+
],
18+
);

0 commit comments

Comments
 (0)