PHP code example of zatxm / validation

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

    

zatxm / validation example snippets


use Zatxm\Validation\Factory as ValidatorFactory;
use Zatxm\Validation\Translator;

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

//初始化工厂对象
$factory = new ValidatorFactory(new Translator($messages));


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

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

$validator = $factory->make($input, $rules, $messages, $attributes);