Mutliple validation not working

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Mutliple validation not working

Marcus James

I am using cakephp version 3, i am trying to add multiple validation but its not working on password field

$validator = new Validator();
                ->requirePresence('email', 'create')
                ->notEmpty('email',['message'=>__('Please enter email address.')])
->add('email', 'email', ['rule' => 'email', 'message'=>__('Please enter valid email address.')])
                ->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table','message'=>__('This Email is already taken.')])
->add('password', [
'length' => [
'rule' => ['minLength', 6],
'message' => 'Password need to be at least 6 characters long',
               ->notEmpty('password',['message'=>__('Please enter password.')])
->add('password','length',['rule' => ['minLength',6],'message' => __('Password should be minimum 6 character long.')])
->requirePresence('repassword', 'create')
->notEmpty('repassword',['message'=>__('Please enter Confirm Password.')])
                    'rule' => function($value, $context) {
                        if (trim($context['repassword']) != trim($context['password'])) {
                            return false;
return true;
                        return false;
                    'message' => __('Password and confirm password did not matched.'),
return $validator;


Sign up for our Newsletter for updates.
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
Like Us on FaceBook
Follow us on Twitter
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit