PHPackages                             meilunzhi/webman-validate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. meilunzhi/webman-validate

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

meilunzhi/webman-validate
=========================

The webman Validate Package

v1(2y ago)04mitPHPPHP &gt;=7.4.0

Since Oct 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/meilunzhi/webman-validate)[ Packagist](https://packagist.org/packages/meilunzhi/webman-validate)[ RSS](/packages/meilunzhi-webman-validate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

webman-validate
===============

[](#webman-validate)

> 基于PHP7.4 + 的Validate实现。基于ThinkPHP6修改的可用于 webman 的通用validate数据验证器。

- 支持助手函数validate(),无需手动创建。
- 支持场景验证scene
- 支持表单令牌token
- 支持unique唯一性验证(基于TP think-orm Db类)
- 支持图片验证

安装
--

[](#安装)

```
composer require meilunzhi/webman-validate
```

使用
--

[](#使用)

> 用法跟ThinkPHP完全一致

\###定义验证器：

```
namespace app\validate;

use meilunzhi\validate\Validate;

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

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

}
```

\##验证器调用代码如下：

```
$data = [
    'name'  => 'thinkphp',
    'age'  => 24,
    'email' => 'thinkphp@163.com'
];
$validate = new \app\validate\User;

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

```

\##助手函数（推荐） 自定义函数 functions.php 添加validate()函数

```
/**
 * @desc 验证器助手函数
 * @param string|array $validate 验证器类名或者验证规则数组
 * @param array $message 错误提示信息
 * @param bool $batch 是否批量验证
 * @param bool $failException 是否抛出异常
 * @return bool
 * @author meilunzhi
 */
function validate($validate = '', array $message = [], bool $batch = false, bool $failException = true)
{
    if (is_array($validate) || ''===$validate) {
        $v = new \meilunzhi\validate\Validate();
        $v->rule($validate);
    } else {
        if (strpos($validate, '.')) {
            [$validate, $scene] = explode('.', $validate);
        }
        $v = new $validate();
        if (!empty($scene)) {
            $v->scene($scene);
        }
    }
     return $v->message($message)->batch($batch)->failException($failException);
}

```

> 验证器调用代码如下：

```
namespace app\controller;

use app\validate\User;
use meilunzhi\validate\exception\ValidateException;

class Index
{
    public function index()
    {
        try {
            validate(User::class)->check([
                'name'  => 'thinkphp',
                'email' => 'thinkphp@qq.com',
            ]);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            dump($e->getError());
        }
    }
}

    //场景校验方法
    $data = [
        'name'  => 'thinkphp',
        'age'   => 10,
        'email' => 'thinkphp@qq.com',
    ];

    try {
        validate(app\validate\User::class)
            ->scene('edit')
            ->check($data);
    } catch (ValidateException $e) {
        // 验证失败 输出错误信息
        dump($e->getError());
    }

    // 静态方法验证
    $validate = \meilunzhi\validate\facade\Validate::rule('age', 'number|between:1,120')
    ->rule([
        'name'  => 'require|max:25',
        'email' => 'email'
    ]);

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

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

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

941d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/638cdc729aead27c32cc905bd1fa84fdc9e8ddb5c7b07aa174af918d715deedb?d=identicon)[SummerMagic](/maintainers/SummerMagic)

---

Top Contributors

[![meilunzhi](https://avatars.githubusercontent.com/u/10607961?v=4)](https://github.com/meilunzhi "meilunzhi (2 commits)")

### Embed Badge

![Health badge](/badges/meilunzhi-webman-validate/health.svg)

```
[![Health](https://phpackages.com/badges/meilunzhi-webman-validate/health.svg)](https://phpackages.com/packages/meilunzhi-webman-validate)
```

###  Alternatives

[rollerworks/password-strength-validator

Password-strength validator for Symfony

1455.7M6](/packages/rollerworks-password-strength-validator)[sllh/iso-codes-validator

Symfony validator wrapper of ronanguilloux/isocodes

37299.8k2](/packages/sllh-iso-codes-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
