Email Validation in CakePHP
Email validation is an important part of any application and especially, when we use email as username in our application and you want to make sure that user enter a valid and unique email address.
In CakePHP application we can define email validation rule in the Model like below:
<?php class User extends AppModel { public $validate = array( 'email' => array( 'mustNotEmpty' => array( 'rule' => 'notEmpty', 'message' => 'Please enter a email.', 'last' => true ) , 'mustBeEmail' => array( 'rule' => array( 'email' ) , 'message' => 'Please enter a valid email', 'last' => true ) , 'mustUnique' => array( 'rule' => 'isUnique', 'message' => 'This email is already exists.', ) ) , ); } ?>