2014-04-16 2 views
0

사용자를 위해 모델의 유효성 검사 규칙을 설정하려면 특수 문자 만 텍스트 필드에 입력하십시오 .so 적절한 해결책을 제안하십시오.Cakephp 특수 문자 유효성 확인

데모 코드는

public function addValidations() 
    { 
     parent::addValidations(); 
     $this->validate['Field name'] = array 
     (
      'notempty' => array 
      (
       'rule' => array('special char', 'msg',), 
       'allowEmpty' => false, 
       'message' => 'Enter Special character only.', 
      ), 
     ); 
    } 
+0

정의 할 수있다? – Raffaele

답변

1

당신이 문자 * 특별한 * 만드는 무엇 Custom Regular Expression Validation

public $validate = array(
    'login' => array(
     'rule' => '/^[\W]+$/', 
     'allowEmpty' => false, 
     'message' => 'Enter Special character only.' 
    ) 
) 
// '/^[\w.-]+$/' this will allow only special character. 
+0

공용 함수 addValidations() { \t \t parent :: addValidations(); \t \t $ this-> 검증 [ 'SeriesConcateCharacter'] = 배열 ​​( \t \t 'SeriesConcateCharacter'=> 어레이 ( \t \t '규칙'=> '/^[\ w] + $ /' \t \t ' allowEmpty '=> false를 \t \t'메시지 '=>'이 특수 문자 만 입력 ' \t \t) \t \t).; } – Amit

+0

작동하지 않습니다. – Amit

+0

은 SeriesConcateCharacter 필드 이름입니다. –