예제 #1
0
<?php

require_once 'validationController.php';
//$_POST['userphone'] = (int) $_POST['userphone'];
//var_dump($_POST);
$POST = array('name' => 'Fred Scuttle', 'age' => 42, 'contact_email' => '             fred@example.com', 'url' => 'http://phpro.org');
/*** an array of rules ***/
$rules_array = array('username' => array('type' => 'string', 'required' => true, 'min' => 6, 'max' => 20, 'trim' => true), 'useremail' => array('type' => 'string', 'required' => true, 'min' => 1, 'max' => 60, 'trim' => true));
//    'userphone'=>array('type'=>'numeric', 'required'=>true, 'min'=>10000000000, 'max'=>20000000000, 'trim'=>true));
/*** a new validation instance ***/
$val = new validation();
/*** use POST as the source ***/
$val->addSource($_POST);
/*** add a form field rule ***/
//$val->addRule('contact_email', 'email', true, 1, 255, true)
//    ->addRule('url', 'url', false, 10, 150, false);
/*** add an array of rules ***/
$val->addRules($rules_array);
/*** run the validation rules ***/
$val->run();
/*** if there are errors show them ***/
if (sizeof($val->errors) > 0) {
    print_r($val->errors);
}
/*** show the array of validated and sanitized variables ***/
print_r($val->sanitized);