PHP code example of houdunwang / validate

1. Go to this page and download the library: Download houdunwang/validate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

houdunwang / validate example snippets


$config = [
	/**
	 * 验证错误显示类型
	 * redirect 直接跳转,会分配$errors到前台
	 * show 直接显示错误信息
	 * default 由开发者自行处理
	 */
	'dispose' => 'redirect',
	//发生错误时的显示模板
	'view'    => 'resource/bug.php'
];
\houdunwang\config\Config::set( 'validate', $config );

\houdunwang\validate\Validate::make(
    [
        ['domain', function ($value) {
            return $value > 100;
        }, '域名不能为空', 3 ]
	]);
//闭包返回 true 时验证通过

\houdunwang\validate\Validate::extend('checkUser',function($field,$value,$params){
	//返回值为true时验证通过
		return true;
});

if(\houdunwang\validate\Validate::fail()){
	echo '验证失败';
};

\houdunwang\validate\Validate::make(array(
        array('username','