function createRegexValidator($regex)
 {
     require_once 'Validation/RegexValidator.php';
     $validator = new RegexValidator();
     $validator->setRegex($regex);
     return $validator;
 }
 function registerValidators(&$validatorManager, &$controller, &$request, &$user)
 {
     $validatorManager->setRequired('account', true, msg('account is required'));
     $regexValidator = new RegexValidator();
     $regexValidator->setParameter('pattern_error', msg('account have invalid character'));
     $regexValidator->setParameter('pattern', PATTERN_ACCOUNT);
     $validatorManager->register('account', $regexValidator);
     $validatorManager->setRequired('password', true, msg('password is required'));
     $validatorManager->setRequired('email', true, msg('email is required'));
     $emailValidator = new EmailValidator();
     $emailValidator->setParameter('email_error', msg('email is wrong'));
     $validatorManager->register('email', $emailValidator);
 }
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     try {
         return parent::validateValue($field, $value);
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $ex) {
         $message = $ex->getMessage();
         $context = $ex->getContext();
         $len = strlen($value);
         if ($this->maxLength === $this->minLength && $len != $this->minLength) {
             $message = 'length must be {0} characters';
             $context = array('{0}' => $this->minLength);
         } else {
             if ($this->minLength < $this->maxLength && ($this->minLength > $len || $len > $this->maxLength)) {
                 $message = 'length must be between {0} and {1} characters';
                 $context = array('{0}' => $this->minLength, '{1}' => $this->maxLength);
             } else {
                 if (is_null($this->maxLength) && $this->minLength > $len) {
                     $message = 'length must be greater than {0} characters';
                     $context = array('{0}' => $this->minLength);
                 } else {
                     if (!is_null($this->maxLength) && $len > $this->maxLength) {
                         $message = 'length must be lower than {0} characters';
                         $context = array('{0}' => $this->maxLength);
                     } else {
                         $message = 'you must set a valid value';
                     }
                 }
             }
         }
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, $message, $context);
     }
 }
 /**
  * Test value and return boolean
  *
  * @param mixed $value
  *
  * @return  boolean
  */
 protected function test($value)
 {
     if (is_bool($value)) {
         return true;
     }
     return parent::test($value);
 }
Beispiel #5
0
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     try {
         return parent::validateValue($field, $value);
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $e) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($e->getField(), $e->getInitialValue(), $e->getValue(), 'you must set a valid email');
     }
 }
 public function validate($value)
 {
     $result = parent::validate($value);
     if (!$result) {
         $this->_setLastError('invalid IPv4 address');
     }
     return $result;
 }
 public function validate()
 {
     try {
         return parent::validate();
     } catch (ValidationException $ex) {
         throw new ValidationException($ex->getInput(), "Input value has to contain only digits.", $ex->getCode(), $ex);
     }
 }
 public function validate()
 {
     try {
         return parent::validate();
     } catch (ValidationException $ex) {
         throw new ValidationException($ex->getInput(), "This is not valid email address.", $ex->getCode(), $ex);
     }
 }
Beispiel #9
0
 public function testPasswordComplexity()
 {
     $regex = '/^[^\\s ]{6,}$/i';
     $valid1 = new RegexValidator('$password$_+123', $regex);
     $valid2 = new RegexValidator('pas123', $regex);
     $invalid1 = new RegexValidator('passw', $regex);
     $invalid2 = new RegexValidator('password123 123', $regex);
     $invalid3 = new RegexValidator('', $regex);
     $valid1->Validate();
     $valid2->Validate();
     $invalid1->Validate();
     $invalid2->Validate();
     $invalid3->Validate();
     $this->assertTrue($valid1->IsValid());
     $this->assertTrue($valid2->IsValid());
     $this->assertFalse($invalid1->IsValid());
     $this->assertFalse($invalid2->IsValid(), "spaces are not allowed");
     $this->assertFalse($invalid3->IsValid(), "password is required are not allowed");
 }
Beispiel #10
0
 public function validateValue(\Ongoo\Component\Form\Field $field, $value)
 {
     if (is_null($value)) {
         return $value;
     }
     try {
         parent::validateValue($field, "{$value}");
     } catch (\Ongoo\Component\Form\Exceptions\ErrorException $e) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($e->getField(), $e->getInitialValue(), $e->getValue(), 'you must set a valid ' . $this->realType, $e->getContext());
     }
     settype($value, $this->type);
     if (!is_null($this->min) && $this->min > $value) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, 'you must a number greater than {0}', array('{0}' => $this->min));
     }
     if (!is_null($this->max) && $this->max < $value) {
         throw new \Ongoo\Component\Form\Exceptions\ErrorException($field, $value, $value, 'you must a number lower than {0}', array('{0}' => $this->max));
     }
 }
 public function __construct()
 {
     parent::__construct('/^[a-zäàáâöôüûñéè0-9!\\#\\$\\%\\&\'\\*\\+\\/\\=\\?\\^_\\`\\{\\|\\}\\~-]+(?:\\.[a-zäàáâöôüûñéè0-9!\\#\\$\\%\\&\'\\*\\+\\/\\=\\?\\^_\\`\\{\\|\\}\\~-]+)*@(?:[a-zäàáâöôüûñéè0-9](?:[a-zäàáâöôüûñéè0-9-]*[a-zäàáâöôüûñéè0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/');
 }
 /**
  * Construct a new URL validator instance
  * @param array $options options for this instance
  * @return null
  */
 public function __construct(array $options = array())
 {
     $this->initRegularExpressions();
     $options[RegexValidator::OPTION_REGEX] = '/^' . $this->regexUrl . '$/';
     parent::__construct($options);
     $this->code = self::CODE;
     $this->message = self::MESSAGE;
 }
 /**
  * {@inheritdoc}
  */
 public function test($value, $context)
 {
     return empty($value) || parent::test($value, $context);
 }
 public function testValidateEmptyValue()
 {
     $val = new RegexValidator('/^[a-z]+$/i');
     $this->assertTrue($val->validate(''));
     $this->assertTrue($val->validate(null));
 }