$subject = array(
'username' => 'shskfhsdjh',
'subArray' => array(
1,2,3
),
'subArray2' => array(
'a1' => 'a',
'a2' => 'b',
)
);
# validate username
$filter->validate('username')->is('alnum');
$filter->validate('username')->is('strlenMin', 6);
--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think you can use one of the below ones1 . Callback https://github.com/auraphp/Aura.Filter/blob/2.x/docs/validate.md#callback and write custom logic if you preferThere is inKeys : https://github.com/auraphp/Aura.Filter/blob/2.x/docs/validate.md#inkeys ( But this probably is not what you are looking for in the case of subArray2 , but may be a combination of inValues and inKeys may help ? )Hari K T
You can ring me : +91 9388 75 8821
http://harikt.com , https://github.com/harikt , http://www.linkedin.com/in/harikt , http://www.xing.com/profile/Hari_KTSkype : kthari85Twitter : harikt
Valitron\Validator::addRule('arrayMin', function($field, $value, array $params, array $fields) { if (count($value) < $params[0]) { return false; } return true;}, 'array size too small');
Valitron\Validator::addRule('inArray', function($field, $value, array $params, array $fields) { print "DEBUG: value:--> ".print_r($value,true)."<-- in params:[" . print_r($params,true)."]\n"; if (in_array($value, $params)) { return true; } return false;}, 'value not in array');
$rules = [
'agentConf.*.groups' => ['required', 'array', ['arrayMin', 2]]
];
$data = <<<ENDDATA { "agentConf": [{ "first_name": "aaaa", "last_name": "bbbbb", "groups": [ "sales", "Other" ], "groupPerms": [ { "Other": [ "111", "222", "333" ] }, { "stats": [ "111" ] }, { "sales": [ "111" ] } ] }] }ENDDATA;
$rules = [ 'agentConf' => ['required', 'array', ['arrayMin', 1]], 'agentConf.*.first_name' => ['required', ['regex', '/.*/']], 'agentConf.*.last_name' => ['required', ['regex', '/.*/']], 'agentConf.*.groups' => ['required', 'array', ['arrayMin', 2]], 'agentConf.*.groups.*' => ['required', ['regex', '/.*/']], 'agentConf.*.groupPerms' => ['required', 'array', ['arrayMin', 3]], 'agentConf.*.groupPerms.*' => ['required', ['inArray', ['Other', 'stats', 'sales']]]];
$data = json_decode($data, true);
$validator = new Valitron\Validator($data);$validator->mapFieldsRules($rules);
if ($validator->validate()) { echo "OK\n";} else { print_r($validator->errors()); print "ERROR\n";}
--
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.