Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 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());
}
Exemplo n.º 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>

Exemplo n.º 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;
     }
 }
Exemplo n.º 6
0
<?php

echo '<pre>';
include '../autoload.php';
use HybridLogic\Validation\Validator;
use HybridLogic\Validation\Rule;
$input = array('notempty' => 'test', 'equal' => 'hello-world', 'notequal' => 'not-goodbye-world', 'matches' => 'test', 'matches2' => 'test', 'inarray' => 'mar', 'inarraykeys' => 'female', 'minlength' => 'testing', 'maxlength' => 'testing', 'exactlength' => 'testing', 'alpha' => 'hello', 'alphanumeric' => 'hello123', 'alphaslug' => 'hello-world-2', 'regex' => 'a2b', 'email' => '*****@*****.**', 'url' => 'http://www.google.com/', 'ip' => '192.168.1.1', 'true' => 'yes', 'number' => '-123.45', 'numnatural' => '27', 'nummin' => '5', 'nummax' => '10', 'numrange' => '7');
$array = array('jan', 'feb', 'mar', 'apr');
$array_keys = array('male' => 'Guys', 'female' => 'Ladies');
$validator = new Validator();
$validator->add_rule('notempty', new Rule\NotEmpty())->add_rule('equal', new Rule\Equal('hello-world'))->add_rule('notequal', new Rule\NotEqual('goodbye-world'))->add_rule('matches', new Rule\Matches('matches2'))->add_rule('inarray', new Rule\InArray($array))->add_rule('inarraykeys', new Rule\InArray($array_keys, $match_keys = true))->add_rule('minlength', new Rule\MinLength(5))->add_rule('maxlength', new Rule\MaxLength(10))->add_rule('exactlength', new Rule\ExactLength(7))->add_rule('alpha', new Rule\Alpha())->add_rule('alphanumeric', new Rule\AlphaNumeric())->add_rule('alphaslug', new Rule\AlphaSlug())->add_rule('regex', new Rule\Regex('/^[a-z][0-9][a-z]/i'))->add_rule('email', new Rule\Email())->add_rule('url', new Rule\URL())->add_rule('ip', new Rule\IP())->add_rule('true', new Rule\True())->add_rule('number', new Rule\Number())->add_rule('numnatural', new Rule\NumNatural())->add_rule('nummin', new Rule\NumMin(5))->add_rule('nummax', new Rule\NumMax(10))->add_rule('numrange', new Rule\NumRange(5, 10));
if ($validator->is_valid($input)) {
    var_dump('success', $validator->get_data());
} else {
    var_dump('error', $validator->get_errors(), $validator->get_data());
}