PHP code example of yd / validation

1. Go to this page and download the library: Download yd/validation 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/ */

    

yd / validation example snippets


$rule = [
	'age'=>['type'=>'int','default'=>0,'vstr'=>'num|>:0'],
	'account'=>['type'=>'str','default'=>'','vstr'=>'must|strIn:word','name'=>'账号必填|账号必须为字母'],
	'email'=>['type'=>'str','default'=>'','vstr'=>'strIs:email'],
	'qq'=>['type'=>'str','default'=>'','vstr'=>'strIs:qq'],
	'ip'=>['type'=>'str','default'=>'','vstr'=>'strIs:ip'],//
	'ip_range'=>['type'=>'str','default'=>'','vstr'=>'strIs:ip_range'],//ip段
	'params'=>[
	    'type'=>'list',
	    'default'=>[],
	    'vstr'=>'count_gt:0',
	    'name'=>'数组必须大于0',
	    'child'=>[
	        'id'=>['type'=>'int','default'=>0,'vstr'=>'must|num|>:0'],      
	    ],
	], 
];
$params = [
	'age'=>1,
	'account'=>'fdsafsdf',
	'email'=>'[email protected]',
	'qq'=>'43546456',
	'ip'=>'10.10.1.1',
	'ip_range'=>'1.1.1.1-3.3.3.3',//支持 1.1.1.1-3.3.3.3 or 1.1.1.1/25
	'params'=>['id'=>0],
];
$data = Valid::make($rule,$params);
var_export($data);