This is my current code.

$rules = array(
    'label'        => 'required',
    'short_name'   => 'required',

$result = ee('Validation')->make($rules)->validate($_POST);

Now I want it like this:

$rules = array(
   'label'        => 'required',
   'short_name'   => 'required|trim|check_name["test_name"]',

but I am getting error in trim rule.

Unknown validation rule trim.

Please help.

1 Answer 1


You are getting error because trim function is not defined in current validation library. You need to add your own function in EE3 before you run validation.

According to the documentation:

You first need to create an object of Validation class.

$validator = ee('Validation')->make();

Then you need to define your custom rule:

$validator->defineRule('trim', function($key, $value, $parameters)
  return ** Depends on result return TRUE or Error Message **;

Then you need to use that rule with setRules.

   'age' => 'required|trim'

Final step is to validate your post data:

$result = $validator->validate($data);

$result will either contains TRUE or object of errors.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.