PHP code example of wkl / validate

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

    

wkl / validate example snippets


private $defaultErrorMsg = [
    'activeUrl' => ':fieldName必须是可访问的网址',
        'alpha' => ':fieldName只能是字母',
        'alphaNum' => ':fieldName只能是字母和数字',
        'alphaDash' => ':fieldName只能是字母数字下划线和破折号',
        'between' => ':fieldName只能在 :arg0 - :arg1 之间',
        'bool' => ':fieldName只能是布尔值',
        'decimal' => ':fieldName只能是小数',
        'dateBefore' => ':fieldName必须在日期 :arg0 之前',
        'dateAfter' => ':fieldName必须在日期 :arg0 之后',
        'equal' => ':fieldName必须等于:arg0',
        'different' => ':fieldName必须不等于:arg0',
        'equalWithColumn' => ':fieldName必须等于:arg0的值',
        'differentWithColumn' => ':fieldName必须不等于:arg0的值',
        'float' => ':fieldName只能是浮点数',
        'func' => ':fieldName自定义验证失败',
        'inArray' => ':fieldName必须在 :arg0 范围内',
        'integer' => ':fieldName只能是整数',
        'isIp' => ':fieldName不是有效的IP地址',
        'notEmpty' => ':fieldName不能为空',
        'numeric' => ':fieldName只能是数字类型',
        'notInArray' => ':fieldName不能在 :arg0 范围内',
        'length' => ':fieldName的长度必须是:arg0',
        'lengthMax' => ':fieldName长度不能超过:arg0',
        'lengthMin' => ':fieldName长度不能小于:arg0',
        'betweenLen' => ':fieldName的长度只能在 :arg0 - :arg1 之间',
        'money' => ':fieldName必须是合法的金额',
        'max' => ':fieldName的值不能大于:arg0',
        'min' => ':fieldName的值不能小于:arg0',
        'regex' => ':fieldName不符合指定规则',
        'allDigital' => ':fieldName只能由数字构成',
        '


 return [
    '


/**
 * Created by PhpStorm.
 * User: root
 * Date: 18-11-19
 * Time: 上午10:47
 */

lidate\Validate();
$validate->addColumn('name')->ol = $validate->validate($data,$langErrorMsgFile); // 验证结果
if ($bool) {
    var_dump("验证通过");
} else {
    var_dump($validate->getError()->__toString());
}
/*
 * 输出结果: string(23) "age的值不能大于18"
 */


/**
 * Created by PhpStorm.
 * User: root
 * Date: 18-11-19
 * Time: 上午10:47
 */

lidate\Validate();
$validate->addColumn('name')->ray && $key == 'age' && $params[$key] == 18;
}, '只允许18岁的进入');
$bool = $validate->validate($data); // 验证结果
if ($bool) {
    var_dump("验证通过");
} else {
    var_dump($validate->getError()->__toString());
}
/*
 * 输出结果: string(23) "只允许18岁的进入"
 */