我需要根据正则表达式验证输入.
//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,4})$/i does not exist.
此外,与Cake 2 Documentation不同,Cake 3.0 validation Documentation中没有提及正则表达式.
这被移动或修改了吗?
试试这个
$validator ->notEmpty('sl_no') ->add('reg_no',[ 'rule' => array('custom','/^([ABCD]{2,4})$/i'),'message' => 'Please enter a valid serial number.' ]);