开发者

CakePHP - Utility method for checking a string is a valid email address?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜