我需要根据正则表达式验证输入。
//Validator
$validator
->notEmpty('sl_no')
->add('reg_no', 'validFormat',[
'rule' => '/^([ABCD]{2,2}[0-9]{4,4})$/i',
'message' => 'Please enter a valid serial number.'
]);
但是我得到以下错误:
Method /^([ABCD]{2,2}[0-9]{4,4})$/i does not exist.
此外,Cake 3.0 validation Documentation 中也没有提到正则表达式。不像Cake 2 Documentation .
这是否已被移动或修改?
最佳答案
试试这个
$validator
->notEmpty('sl_no')
->add('reg_no', 'validFormat',[
'rule' => array('custom', '/^([ABCD]{2,2}[0-9]{4,4})$/i'),
'message' => 'Please enter a valid serial number.'
]);
关于php - CakePHP 3.0 - 正则表达式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067425/