0
我們已經嘗試了幾種驗證密碼的解決方案,但都沒有工作,但用戶登錄後,除密碼中的字母數字驗證外,所有驗證都可以正常工作。cakephp代碼不能用於字母數字驗證
這裏是代碼:使用自定義功能,這是行不通的
'password' => array ('required' => array (
'rule' => array ('notEmpty'),
'rule' => array ('between',1,15),
//'rule' => array('custom', '[a-zA-Z0-9, ]+'),
'message' => 'A password is required,must be between 8 to 15 characters')
),
因此我們嘗試在模型
'alphaNumeric' => array(
'rule' => array('alphaNumericDashUnderscore'),
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'password must contain Alphabets and numbers only'
)),
自定義函數
public function alphaNumericDashUnderscore($check) {
$value = array_values($check);
$value = $value[0];
return preg_match('|^[0-9a-zA-Z_-]*$|', $value);
}
我們介紹CakePHP版本工作2.4.3