// Checking if a string only contains letters and spaces use Cake\Validation\Validator; $validator = new Validator(); $validator->add('name', [ 'format' => [ 'rule' => ['custom', '/^[a-zA-Z\s]+$/'], 'message' => __('Only letters and spaces allowed') ] ]); $errors = $validator->errors(['name' => 'John Doe']); // $errors will be empty array because 'John Doe' is a valid name // Checking if a password is at least 8 characters long $validator->add('password', [ 'length' => [ 'rule' => ['minLength', 8], 'message' => __('Passwords must be at least 8 characters long') ] ]); $errors = $validator->errors(['password' => 'password']); // $errors will contain the error message because 'password' is too short // Checking if an email is valid $validator->add('email', [ 'email' => [ 'rule' => 'email', 'message' => __('Please enter a valid email address') ] ]); $errors = $validator->errors(['email' => 'email@example.com']); // $errors will be empty array because 'email@example.com' is a valid emailThe package library for the CakePHP validation library is `cakephp/cakephp`.