In a controller, I need to check a string to see if it is a valid email address. Is there an existing method开发者_开发技巧 in Cake that I can use to check this?
It has nothing to do with models, so I don't want to use a validate array.
I found the core Validation class. Validation::email()
App::uses('Validation', 'Utility');
class MyController extends AppController
{
public function myAction()
{
$isValid = Validation::email('person@example.com'); // Returns true or false
}
}
you may still use the model validation for it
$this->Model->set($data);
if ($this->Model->validates()) {}
your current model should have a rule for "email" if you are handling emails in this controller. or you can create one here.
精彩评论