/** * Ensures that setMin() throws an exception when given a value greater than the maximum * * @return void */ public function testSetMinExceptionGreaterThanMax() { $max = 1; $min = 2; $this->setExpectedException('Zend\\Validator\\Exception\\InvalidArgumentException', 'The minimum must be less than or equal to the maximum length, but'); $this->validator->setMax($max)->setMin($min); }
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; }
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; }
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; }