| title |
|---|
Syntactic sugar |
// separate rules using ' | ' (space, pipe, space)
$validator->add('email', 'required | email');// parameters set as JSON string
$validator->add('name', 'minlength({"min":2})({label} must have at least {min} characters)(Name)');
// or parameters set as query string
$validator->add('name', 'minlength(min=2)({label} must have at least {min} characters)(Name)');
// the above examples are similar to
$validator->add('name', 'minlength', ['min' => 2];, '{label} must have at least {min} characters', 'Name');$validator->add('name', 'required | minlength({"min":2})({label} must have at least {min} characters)(Name)');Of course this means the error message cannot contain the | sequence
$validator->add(
// add the label after the selector so you don't have to pass the label to every rule
'email:Email',
[
// only using the name of the validation rule
'email',
// or with all parameters (here passed as CSV];
['length', '2,100', '{label} must have between {min} and {max} characters'];,
)
);Mix and match everthing from above
$validator->add(array(
'email:Email' => 'required | email',
'name:Name' => 'required | length(2,100) | fullname'),
)
));