PHPackages                             vloop/yii2-custom-validators - 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. vloop/yii2-custom-validators

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

vloop/yii2-custom-validators
============================

Custom validators for Yii2 projects

v1.0.2(3y ago)026MITPHPPHP &gt;=7.0

Since Jul 21Pushed 3y agoCompare

[ Source](https://github.com/VitalyLitvinov74/yii2-custom-validators)[ Packagist](https://packagist.org/packages/vloop/yii2-custom-validators)[ RSS](/packages/vloop-yii2-custom-validators/feed)WikiDiscussions main Synced 1mo ago

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

yii2-custom-validators
======================

[](#yii2-custom-validators)

```
rules() {
   return
       [
          'data',
          ArrayValidator::class,
          'subRules' => [
              [['foo', 'bar'], 'required'],
              [
                  'foo',                                         // associative array
                  ArrayValidator::class,
                  'subRules' => [
                      ['id', 'required'],
                      ['id', 'integer'],
                  ],
              ],
              ['bar', 'string'],
              [
                  'payments',                                     // non-associative array
                  CustomEachValidator::class,
                  'rule' => [
                      ArrayValidator::class,
                      'subRules' => [
                          [['type', 'sum'], 'required'],
                          ['type', 'in', 'range' => [1, 2, 3]],
                          ['sum', 'double'],
                      ],
                  ],
              ],
              [
                  'client',
                  ArrayValidator::class,
                  'subRules' => [                                // using closure inside 'when'. $client - internal validation model
                      ['email', 'required', 'message' => '[email] cannot be blank when [phone] is blank', 'when' => static function($client) {
                          return empty($client->phone);
                      }],
                      ['phone', 'required', 'message' => '[phone] cannot be blank when [email] is blank', 'when' => static function($client) {
                          return empty($client->email);
                      }],
                      ['email', 'email'],
                      ['phone', PhoneInputValidator::class],
                      ['email', function($attribute, $params) {  // Using a closure as a validator. $this - internal validation model
                          if ($this->$attribute === 'test@example.com') {
                              $this->addError("forbidden $attribute value was passed");
                          }
                      }],
                  ],
              ],
          ],
        ]
}

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% 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 ~1 days

Total

3

Last Release

1390d ago

### Community

Maintainers

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

---

Top Contributors

[![levkagm](https://avatars.githubusercontent.com/u/14794360?v=4)](https://github.com/levkagm "levkagm (5 commits)")[![VitalyLitvinov74](https://avatars.githubusercontent.com/u/42306308?v=4)](https://github.com/VitalyLitvinov74 "VitalyLitvinov74 (3 commits)")

---

Tags

validationyii2validate array

### Embed Badge

![Health badge](/badges/vloop-yii2-custom-validators/health.svg)

```
[![Health](https://phpackages.com/badges/vloop-yii2-custom-validators/health.svg)](https://phpackages.com/packages/vloop-yii2-custom-validators)
```

###  Alternatives

[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)[cebe/yii2-lifecycle-behavior

Define the lifecycle of a model by defining allowed satus changes in terms of a state machine.

5119.8k1](/packages/cebe-yii2-lifecycle-behavior)[arogachev/yii2-many-to-many

Many-to-many ActiveRecord relation for Yii 2 framework

3541.2k4](/packages/arogachev-yii2-many-to-many)

PHPackages © 2026

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