can we create validation rules, which can work as a core validation rule.
Suppose I want to use a validation function which can be use for input fields.Means I have a function like:
function checkinput($input)
{
$arr=array('x','y','z');
if(in_array($input,$arr))
return false;
else
return true;
}
Now I want to use this function as the validation in all models. suppose for this function a custom rule has been created, name checkinput.
I want to use this validation in any model as:
var $validate = array(
'name' => array(
'notempty' => array(
'rule' => 'notEmpty',
'message' => 'Please provide a name.',
),
'checkinput' => array(
'rule' => 'checkinput',
'message' => "You can't use X,Y,Z as name.",
),
));
Can this kind of custom validation rule be created in behaviour or by other method..
This should help you: “Custom validation rules”
http://www.dereuromark.de/2010/07/19/extended-core-validation-rules/
and
http://www.dereuromark.de/2011/10/07/maximum-power-for-your-validation-rules/
with code in github
Note that you need to array_shift first (see debug output for details):