Search code examples
phpcakephpcakephp-1.3email-validation

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.


Solution

  • I found the core Validation class. Validation::email()

    App::uses('Validation', 'Utility');
    
    class MyController extends AppController
    {
        public function myAction()
        {
            $isValid = Validation::email('[email protected]'); // Returns true or false
        }
    }