Example #1
0
 /**
  * Tests Keys
  *
  * @return void
  * @dataProvider provider
  **/
 public function testKeys($input, $expected)
 {
     $array = array('jan' => 'january', 'feb' => 'february', 'mar' => 'march', 'apr' => 'april', 'jun' => 'june');
     $validator = new Validator();
     $validator->add_rule('field', new Rule\InArray($array, $match_keys = true));
     $result = $validator->is_valid($input);
     $this->assertEquals($expected, $result);
 }
 /**
  * Test Rules
  *
  * @return void
  * @dataProvider providerRules
  **/
 public function testRules($input, $expected)
 {
     $validator = new Validator();
     $validator->add_rule('field1', new Rule\NotEmpty());
     $validator->add_rule('field2', new Rule\MinLength(5));
     $validator->add_rule('field2', new Rule\MaxLength(10));
     $result = $validator->is_valid($input);
     $this->assertEquals($expected, $result);
 }
Example #3
0
<?php

echo '<pre>';
include '../autoload.php';
use HybridLogic\Validation\Validator;
use HybridLogic\Validation\Rule;
$input = array('name' => 'Luke ', 'email' => ' LuKe@lUkElAnChEsTeR.CO.UK ', 'password' => 'password123', 'password2' => 'password456');
$validator = new Validator();
$validator->set_label('name', 'your name')->set_label('password2', 'password confirmation')->add_filter('name', 'trim')->add_filter('email', 'trim')->add_filter('email', 'strtolower')->add_rule('name', new Rule\MinLength(5))->add_rule('name', new Rule\MaxLength(10))->add_rule('email', new Rule\MinLength(5))->add_rule('email', new Rule\Email())->add_rule('password', new Rule\Matches('password2'));
if ($validator->is_valid($input)) {
    var_dump('success', $validator->get_data());
} else {
    var_dump('error', $validator->get_errors(), $validator->get_data());
}
Example #4
0
<?php

include '../autoload.php';
use HybridLogic\Validation\Validator;
use HybridLogic\Validation\Rule;
$validator = new Validator();
$validator->set_label('name', 'your name')->add_filter('name', 'trim')->add_rule('name', new Rule\NotEmpty())->add_rule('name', new Rule\MinLength(5))->add_rule('name', new Rule\MaxLength(10))->add_filter('email', 'trim')->add_filter('email', 'strtolower')->add_rule('email', new Rule\NotEmpty())->add_rule('email', new Rule\MinLength(5))->add_rule('email', new Rule\Email())->add_rule('age', new Rule\NotEmpty())->add_rule('age', new Rule\NumRange(13, 18))->add_rule('password', new Rule\NotEmpty())->add_rule('password', new Rule\MinLength(5))->add_rule('password', new Rule\Matches('password2'))->set_label('password2', 'password confirmation');
if (isset($_POST['submit'])) {
    if ($validator->is_valid($_POST)) {
        echo '<p>Posted successfully.</p>';
    } else {
        echo '<p>Errors were encountered:</p><ul>';
        foreach ($validator->get_errors() as $error) {
            echo "<li>{$error}</li>";
        }
        echo '</ul>';
    }
}
$jquery_validator = new HybridLogic\Validation\ClientSide\jQueryValidator($validator);
$jquery = $jquery_validator->generate();
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
	<meta charset="utf-8">
	<title>jQuery Validation Test</title>
</head>

<body>

Example #5
0
 private function validate($data)
 {
     $validator = new Validator();
     $validator->add_rule('password', new Rule\NotEmpty())->add_rule('password', new Rule\MinLength(6))->add_rule('email', new Rule\NotEmpty())->add_rule('email', new Rule\Email())->add_rule('group', new Rule\AlphaNumeric())->add_rule('status', new Rule\AlphaNumeric())->add_rule('confirmation', new Rule\AlphaNumeric());
     if ($validator->is_valid($data)) {
         return true;
     } else {
         $this->bcms->flash('error', print_r($validator->get_errors(), true));
         return false;
     }
 }