コード例 #1
0
ファイル: StringLengthTest.php プロジェクト: pnaq57/zf2demo
 /**
  * Ensures that setMax() throws an exception when given a value less than the minimum
  *
  * @return void
  */
 public function testSetMaxExceptionLessThanMin()
 {
     $max = 1;
     $min = 2;
     $this->setExpectedException('Zend\\Validator\\Exception\\InvalidArgumentException', 'The maximum must be greater than or equal to the minimum length, but ');
     $this->validator->setMin($min)->setMax($max);
 }
コード例 #2
0
 private function validarCampo($valorCampo, array $outrosCampos = array())
 {
     if (isset($outrosCampos['repetir']) && $outrosCampos['repetir'] == 'S') {
         if (empty($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_REQUERIDA);
             return false;
         }
     } elseif (isset($outrosCampos['repetir']) && $outrosCampos['repetir'] == 'N') {
         if (!empty($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_NAO_INFORMAR);
             return false;
         }
     }
     if (!empty($valorCampo)) {
         $stringLenght = new StringLength();
         $stringLenght->setMin('3');
         $stringLenght->setMax('3');
         $stringLenght->setEncoding("UTF-8");
         if (!$stringLenght->isValid($valorCampo)) {
             $this->error(self::MSG_DESPESA_REPETIR_QUANDO_VALOR_INVALIDO);
             return false;
         }
     }
     return true;
 }
コード例 #3
0
ファイル: RegisterFilter.php プロジェクト: shashi99/ZF2Demo
 public function getInputFilter()
 {
     $maxvalidator = new Validator\StringLength();
     $maxvalidator->setMax(50);
     $minvalidator = new Validator\StringLength();
     $minvalidator->setMin(4);
     $email = new Input('email');
     $email->getValidatorChain()->attach(new Validator\EmailAddress());
     $email->getValidatorChain()->attach($maxvalidator);
     $email->getValidatorChain()->attach($minvalidator);
     $password = new Input('password');
     $password->getValidatorChain()->attach($maxvalidator);
     $password->getValidatorChain()->attach(new Validator\StringLength(array('min' => 6)));
     $first_name = new Input('first_name');
     $first_name->getValidatorChain()->attach($maxvalidator);
     $first_name->getValidatorChain()->attach($minvalidator);
     $user_name = new Input('username');
     $user_name->getValidatorChain()->attach($maxvalidator);
     $user_name->getValidatorChain()->attach($minvalidator);
     $inputFilter = new InputFilter();
     $inputFilter->add($email);
     $inputFilter->add($password);
     $inputFilter->add($first_name);
     $inputFilter->add($user_name);
     return $inputFilter;
 }
コード例 #4
0
ファイル: AddPost.php プロジェクト: samija/Deeplifec4tk
 /**
  * @return ValidatorChain
  */
 protected function getTitleValidatorChain()
 {
     $stringLength = new StringLength();
     $stringLength->setMin(5);
     $validatorChain = new ValidatorChain();
     //        $validatorChain->attach(new Alnum(true));
     $validatorChain->attach($stringLength);
     return $validatorChain;
 }
コード例 #5
0
ファイル: NewPassword.php プロジェクト: kristjanAnd/SimpleIV
 public function getInputFilter()
 {
     if ($this->filter == null) {
         $this->filter = new InputFilter();
         $password = new Input('password');
         $password->setRequired(true);
         $password->setAllowEmpty(false);
         $length = new StringLength();
         $length->setMax(20);
         $length->setMin(5);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_LONG);
         $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_SHORT);
         $password->getValidatorChain()->attach($length);
         $this->filter->add($password);
         $passowordRepeat = new Input('passwordRepeat');
         $passowordRepeat->setRequired(true);
         $passowordRepeat->setAllowEmpty(false);
         $passowordRepeat->getValidatorChain()->attach(new Identical('password'));
         $this->filter->add($passowordRepeat);
     }
     return $this->filter;
 }