Wednesday, March 2, 2022

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

Issue

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.


Solution

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


Answered By - BadHorsie

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.