PHP code example of wisonlau / validation

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

    

wisonlau / validation example snippets


$messages = [
    'accepted'             => ':attribute 必须接受。',
    'active_url'           => ':attribute 不是一个有效的网址。',
    'after'                => ':attribute 必须是一个在 :date 之后的日期。',
    'alpha'                => ':attribute 只能由字母组成。',
    'alpha_dash'           => ':attribute 只能由字母、数字和斜杠组成。',
    'alpha_num'            => ':attribute 只能由字母和数字组成。',
    // ...
];

//初始化工厂对象
$factory = new ValidatorFactory($data, $rules, $attributes, 'validate', $messages, 'zh_cn');


$attributes = [
    'username' => '用户名',
    'password' => '密码',
];

$rules = [
    'username' => 'factory 的时候已经设置了消息,则留空即可

$factory = new ValidatorFactory($input, $rules, $attributes, 'make', $messages);

$factory = new ValidatorFactory($input, $rules, $attributes, 'make', $messages);
$factory->extend();