PHPackages                             flatphp/validation - 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. flatphp/validation

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

flatphp/validation
==================

light validator

v1.0.0(6y ago)17MITPHPPHP &gt;=5.5

Since Mar 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/flatphp/validation)[ Packagist](https://packagist.org/packages/flatphp/validation)[ RSS](/packages/flatphp-validation/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (2)Used By (0)

validation
==========

[](#validation)

light validator

Install
=======

[](#install)

```
composer require flatphp/validation

```

Usage
=====

[](#usage)

```
use \Flatphp\Validation\Validator;

// data value
$data = ['username' => 'tom', 'email' => '', 'password' => '', 'age' => 10];

// validate rules (验证规则和错误消息)
$rules = array(
    'username' => ['required|length:3,20', array('required' => 'username required', 'length' => 'length range 3-20')],
    'email' => ['email', 'invalid email'],
    'password' => 'required'
);

// validate
$res = Validator::validate($data, $rules, $failed);

// if failed echo failed message
if (!$res) {
    echo $failed['msg'];
}

// failed is referenced value if fail, format: ['on' => 'required', 'msg' => 'username required']
```

failed referenced value $failed 格式
----------------------------------

[](#failed-referenced-value-failed-格式)

```
// failed e.g.
array(
    'on' => 'required',
    'msg' => 'username required'
)

```

single value validate
---------------------

[](#single-value-validate)

```
use \Flatphp\Validation\Validator;
$value = 'hello';
$res = Validator::validateOne($value, 'required|length:2,20', array(
    'required' => 'cannot be empty',
), $failed);
```

simple use
----------

[](#simple-use)

```
$res = Validator::isEmail('test@gmail.com');
```

How to custom your own validate method 加入定制自己的验证方法
==================================================

[](#how-to-custom-your-own-validate-method-加入定制自己的验证方法)

- Just extends Validator class and add your own method (继承)
- Or Just write global function (写全局函数) *notes:*method|function should be like isXxx($value) or isXxx($value, $params), example:
    方法或函数格式必须是这样的，参考以下：

```
function isZero($value)
{
    return $value === 0;
}

function isHasstr($value, $param)
{
    return strpos($value, $param) !== false;
}
```

Methods 已有的方法和规则
================

[](#methods-已有的方法和规则)

methodrulenoteisRequiredrequireexcept 0isNotemptynotemptyjust empty() checkisEmailemailisDatedateisDatetimedatetimeisUrlurlisMatchmatchpreg\_match pattenisLengthlengthsecond parameter is the length range, e.g. 10,20isRangerangesecond parameter is range, e.g. 10,20isBoolbool\[true, false, 0, 1, '0', '1'\]isStringstringisIntintisNumericnumericisArrayarrayisEqualequal==isSamesame===isIpipisJsonjsonisIninsecond parameter e.g. aa,bb,ccisNotinnotin

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

2261d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3e4d193838370dbe5119947cb84acd917f9e7dd4baf5ed9d0dbc88f26310fa5?d=identicon)[fredyang](/maintainers/fredyang)

---

Top Contributors

[![shukyoo](https://avatars.githubusercontent.com/u/2231396?v=4)](https://github.com/shukyoo "shukyoo (3 commits)")

---

Tags

validatorvalidation

### Embed Badge

![Health badge](/badges/flatphp-validation/health.svg)

```
[![Health](https://phpackages.com/badges/flatphp-validation/health.svg)](https://phpackages.com/packages/flatphp-validation)
```

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[vlucas/valitron

Simple, elegant, stand-alone validation library with NO dependencies

1.6k4.4M128](/packages/vlucas-valitron)[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M30](/packages/wixel-gump)

PHPackages © 2026

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