@@ -5,7 +5,7 @@ This is validator add-on for Agile Data (https://github.com/atk4/data).
55It uses https://github.com/vlucas/valitron under the hood.
66
77
8- [ ![ Build Status] ( https://travis-ci.org/atk4/validate.png?branch=master )] ( https://travis-ci.org/atk4/validate )
8+ [ ![ Build Status] ( https://travis-ci.org/atk4/validate.png?branch=develop )] ( https://travis-ci.org/atk4/validate )
99[ ![ Code Climate] ( https://codeclimate.com/github/atk4/validate/badges/gpa.svg )] ( https://codeclimate.com/github/atk4/validate )
1010[ ![ StyleCI] ( https://styleci.io/repos/161695320/shield )] ( https://styleci.io/repos/161695320 )
1111[ ![ CodeCov] ( https://codecov.io/gh/atk4/validate/branch/develop/graph/badge.svg )] ( https://codecov.io/gh/atk4/validate )
@@ -31,14 +31,14 @@ $v = new \atk4\validate\Validator($model);
3131
3232// set simple validation rule for one field
3333// ->rule($field, $rules)
34- $v->rule('name', ['required','lengthMin'=>3 ]);
34+ $v->rule('name', [ 'required', [ 'lengthMin', 3] ]);
3535
3636// set multiple validation rules in one shot
3737// ->rules($array_of_rules) // [field=>rules]
3838$v->rules([
39- 'name' => ['required', 'lengthMin'=>3 ],
40- 'age' => ['integer', 'min'=>0, 'max'=>99 ],
41- 'tail_length' => ['integer', 'min'=>0 ],
39+ 'name' => ['required', [ 'lengthMin',3] ],
40+ 'age' => ['integer', [ 'min',0], [ 'max',99] ],
41+ 'tail_length' => ['integer', [ 'min',0] ],
4242]);
4343
4444// set validation rules based on value of another field
@@ -48,13 +48,18 @@ $v->if(['type'=>'dog'], [
4848 'age' => ['required'],
4949 'tail_length' => ['required'],
5050], [
51- 'tail_length' => ['equals'=>'' ], // balls don't have tail
51+ 'tail_length' => [ [ 'equals',''] ], // balls don't have tail
5252]);
5353
5454// you can also pass multiple conditions which will be treated as AND conditions
5555$v->if(['type'=>'dog', 'age'=>50], $rules_if_true, $rules_if_false);
56+
57+ // you can also set custom error message like this:
58+ $v->rule('age', [ ['min', 3, 'message'=>'Common! {field} to small'] ]);
59+ // and you will get this "Common! Age to small"
5660```
5761
5862You can also pass callback instead of array of rules.
63+ Callback receives these parameters $field, $value, $args, $data and should return true/false.
5964
6065See ` /tests ` folder for more examples.
0 commit comments