CakePHP 3.6和RexEx验证器规则

时间:2018-11-06 17:45:46

标签: regex cakephp cakephp-3.0

我在看这个问题:CakePHP 3 regex validation

我无法获得类似的功能。似乎绕过了规则:

$validator
        ->scalar('password')
        ->add('password', 'custom',[
            'rule' => function ($value, $context) {
                return !preg_match('/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@$.!?#]).{8,}$/i', $value);
            },
            'message' => 'Password must be at least 8 characters long.'
        ])
        ->maxLength('password', 255)
        ->requirePresence('password', 'create', 'This field is required.')
        ->notEmpty('password');

有人可以帮我解决我做错的事情吗?

0 个答案:

没有答案