Example #1
0
 static function password($password1, $password2, $rules = [])
 {
     $error = new ValidationError();
     if ($password1 != $password2) {
         $error->add('Wachtwoorden komen niet overeen');
     }
     if (!empty($rules)) {
         if (isset($rules['min_length'])) {
             if (strlen($password1) < $rules['min_length']) {
                 $error->add('Wachtwoord moet langer zijn dan ' . $rules['min_length']);
             }
         }
         if (isset($rules['special_chars'])) {
             if (!preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $password1)) {
                 $error->add('Wachtwoord moet speciaale karakters hebben');
             }
         }
     }
     if (count($error->errors) == 0) {
         return true;
     } else {
         return $error;
     }
 }
Example #2
0
 /**
  * @param string $field
  * @param string $msg
  * @return Hypercharge\Errors\ValidationError
  */
 static function create($field, $msg)
 {
     $e = new ValidationError();
     $e->add($field, $msg);
     $e->flush();
     return $e;
 }
 function testValidationErrorAdd()
 {
     $errors = array();
     $e = new ValidationError();
     $this->assertEqual($e->message, '0 validation errors');
     $this->assertEqual($e->technical_message, '');
     $this->assertEqual($e->errors, $errors);
     $this->assertFalse($e->flush());
     $this->assertEqual($e->message, '0 validation errors');
     $this->assertEqual($e->technical_message, '');
     $errors[] = array('property' => 'a', 'message' => 'msg a');
     $e->add('a', 'msg a');
     $this->assertTrue($e->flush());
     $this->assertEqual($e->message, '1 validation error');
     $this->assertEqual($e->technical_message, '1 affected property: a');
     $this->assertEqual($e->errors, $errors);
     $errors[] = array('property' => 'b', 'message' => 'msg b');
     $e->add('b', 'msg b');
     $this->assertTrue($e->flush());
     $this->assertEqual($e->message, '2 validation errors');
     $this->assertEqual($e->technical_message, '2 affected properties: a, b');
     $this->assertEqual($e->errors, $errors);
 }