0

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
}

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0
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.
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.