Annabelle
Annabelle

Reputation: 754

CakePHP 3.x calling standard validation rules in own validation rules

How can I call the CakePHP 3.x built-in 'rule'=>'email' inside of my own validation rule? I would like to make this check among other customized checks not in e.g. validationDefault function.

public function myValidationRule($value,$context){   
   // HERE -- how can I call standard email rule
}

Upvotes: 0

Views: 122

Answers (2)

ndm
ndm

Reputation: 60453

Except for requirePresence, allowEmpty and notEmpty, all built-in rules map to corresponding static methods on the \Cake\Validation\Validation class, which you can invoke manually yourself if necessary.

The email rule uses Validation::email(), so you can use it like

public function myValidationRule($value, $context) {   
   // ...
   $isValid = \Cake\Validation\Validation::email($value);
   // ...
}

See also

Upvotes: 2

user6613363
user6613363

Reputation:

public function myValidationRule($value,$context){   
   // HERE -- you can get your email in $value and other values in $context
   // HERE you can add any of your custome validation rule 
   // for example
   return $value==null;
   // it will return true if your email is null.
}

Upvotes: 0

Related Questions