2017 © Pedro Peláez
 

library think-validate

think validate

image

topthink/think-validate

think validate

  • Friday, March 9, 2018
  • by topthink
  • Repository
  • 5 Watchers
  • 11 Stars
  • 1,261 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 173 % Grown

The README.md

think-validate

基于PHP5.6+ 的Validate实现, (*1)

安装

composer require topthink/think-validate

用法

use think\Validate;

$validate = Validate::make([
    'name'  => 'require|max:25',
    'email' => 'email'
]);

$data = [
    'name'  => 'thinkphp',
    'email' => 'thinkphp@qq.com'
];

if (!$validate->check($data)) {
    var_dump($validate->getError());
}

支持创建验证器进行数据验证, (*2)

<?php
namespace app\index\validate;

use think\Validate;

class User extends Validate
{
    protected $rule =   [
        'name'  => 'require|max:25',
        'age'   => 'number|between:1,120',
        'email' => 'email',    
    ];

    protected $message  =   [
        'name.require' => '名称必须',
        'name.max'     => '名称最多不能超过25个字符',
        'age.number'   => '年龄必须是数字',
        'age.between'  => '年龄只能在1-120之间',
        'email'        => '邮箱格式错误',    
    ];

}

验证器调用代码如下:, (*3)

$data = [
    'name'  => 'thinkphp',
    'email' => 'thinkphp@qq.com',
];

$validate = new \app\index\validate\User;

if (!$validate->check($data)) {
    var_dump($validate->getError());
}

更多用法可以参考5.1完全开发手册的验证章节, (*4)

The Versions

09/03 2018

dev-master

9999999-dev

think validate

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0

 

by liu21st

17/11 2017

1.0.1

1.0.1.0

think validate

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0

 

by liu21st

17/11 2017

1.0

1.0.0.0

think validate

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0

 

by liu21st