PHP code example of lsys / validation

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

    

lsys / validation example snippets


use LSYS\Validation;
=array(
	"username"=>"ddddd",
);
$validation = Validation::factory($data); 
//给字段添加别名,显示用
$validation->label("username",__("username"));
//添加判断规则
$validation->rule('username', 'not_empty')
	->rule('username', 'min_length', array(':value', 4))
	->rule("username",function($valid,$value){
	//自定义校验函数
	//添加错误消息,校验未通过时赋值
	$valid->error("username", "bbbb");
	$valid->message("username.bbbb",__("bad msg"));
	},array(':validation',':value')/*第三个参数为参数定义*/);
//进行校验
if (!$validation->check()){
	//校验未通过
	print_r($validation->errors(TRUE));
}