本文整理匯總了PHP中validation::addRules方法的典型用法代碼示例。如果您正苦於以下問題:PHP validation::addRules方法的具體用法?PHP validation::addRules怎麽用?PHP validation::addRules使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類validation
的用法示例。
在下文中一共展示了validation::addRules方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array
<?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);