PHPackages                             codeonyii/yii2-at-least-validator - 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. codeonyii/yii2-at-least-validator

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

codeonyii/yii2-at-least-validator
=================================

Validates at least one (or more) attributes.

v1.2.6(7y ago)28253.5k—3.5%20[4 issues](https://github.com/sdlins/yii2-at-least-validator/issues)[2 PRs](https://github.com/sdlins/yii2-at-least-validator/pulls)1Apache-2.0PHPPHP &gt;=5.6

Since May 14Pushed 5y ago5 watchersCompare

[ Source](https://github.com/sdlins/yii2-at-least-validator)[ Packagist](https://packagist.org/packages/codeonyii/yii2-at-least-validator)[ Docs](https://github.com/code-on-yii/yii2-at-least-validator)[ RSS](/packages/codeonyii-yii2-at-least-validator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (18)Used By (1)

Yii 2 - AtLeastValidator
========================

[](#yii-2---atleastvalidator)

[![Latest Stable Version](https://camo.githubusercontent.com/51820fc81d9cf8cfe4c0b36c85d151591d95044fda314704f7047c704d78a93e/68747470733a2f2f706f7365722e707567782e6f72672f636f64656f6e7969692f796969322d61742d6c656173742d76616c696461746f722f762f737461626c65)](https://packagist.org/packages/codeonyii/yii2-at-least-validator)[![Total Downloads](https://camo.githubusercontent.com/0152c8725339e88632905cd9dc115a2c11e7baf9cad514d2d84f412e253f5c7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656f6e7969692f796969322d61742d6c656173742d76616c696461746f722e737667)](https://packagist.org/packages/codeonyii/yii2-at-least-validator)[![Build Status](https://camo.githubusercontent.com/19562e54401ef9d4b5548dccfb8652fb7ff8a3a879723835a2ba7e94fbaaece1/68747470733a2f2f7472617669732d63692e6f72672f736c696e73746a2f796969322d61742d6c656173742d76616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/slinstj/yii2-at-least-validator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/74d5b192421ca442723eea9763d942d7a62c9144b2f313306ea25e2742e1103b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736c696e73746a2f796969322d61742d6c656173742d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/slinstj/yii2-at-least-validator/?branch=master)[![CodeFactor](https://camo.githubusercontent.com/4cedfa8cdfb075842d4d7a66278ab901bb187dd587cbe4fe5a7be9250ac644c1/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f736c696e73746a2f796969322d61742d6c656173742d76616c696461746f722f6261646765)](https://www.codefactor.io/repository/github/slinstj/yii2-at-least-validator)

Sometimes, in a set of fields, you need to make at least one of them (sometimes two, or more) be filled. For example, phone OR e-mail, (facebook OR linkedin) OR (linkedin OR instagram) and so on. You can do it using required validator with a bunch of conditional rules. Or you can use AtLeastValidator.

Installation
------------

[](#installation)

Use composer:

```
    composer require "codeonyii/yii2-at-least-validator"
```

In your Model, import the validator:

```
use codeonyii\yii2validators\AtLeastValidator;

class MyModel extends Model
{
...
    public function rules()
    {
        // see examples below
    }
...
```

Examples
--------

[](#examples)

In the following example, the `phone` and `email` attributes will be verified. If none of them are filled `phone` will receive an error. Please, note that `in` param is always mandatory.

```
     // in rules()
     return [
         ['phone', AtLeastValidator::className(), 'in' => ['phone', 'email']],
     ];
```

Here, `facebook`, `linkedin` and `instagram` attributes will be verified. If at least 2 (note the `min` param) of them are not filled, `facebook` and `instagram` will receive an error:

```
     // in rules()
     return [
         [['facebook', 'instagram'], AtLeastValidator::className(), 'in' => ['facebook', 'linkedin', 'instagram'], 'min' => 2],
     ];
```

### Showing errors in summary

[](#showing-errors-in-summary)

If you want to show errors in a summary instead in the own attributes, you can do this:

*Note that summary will **not** work for client-side validation. If you want to use it, you should disable the client-side validation for your fields or for your entire form.*

```
     // in the rules()
     // please note the exclamation mark. It will avoid the pk attribute to be massively assigned.
     return [
         ['!id', AtLeastValidator::className(), 'in' => ['attr1', 'attr2', 'attr3']], // where `id` is the pk
     ];

     // in the view, show all errors in the summary:
     ...
     echo yii\helpers\Html::errorSummary($model, ['class' => ['text-danger']]);

     // OR, to show only `id` errors:
     echo yii\helpers\Html::error($model, 'id', ['class' => ['text-danger']]);
```

Changelog
---------

[](#changelog)

Please, access [Releases](https://github.com/code-on-yii/yii2-at-least-validator/releases) to see versions with a some description.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor5

5 contributors hold 50%+ of commits

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 ~64 days

Recently: every ~30 days

Total

14

Last Release

2824d ago

PHP version history (2 changes)1.2.3PHP ^5.6 || ^7.0 || ^7.1

1.2.4PHP &gt;=5.6

### Community

Maintainers

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

---

Top Contributors

[![airani](https://avatars.githubusercontent.com/u/438573?v=4)](https://github.com/airani "airani (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![craiglondon](https://avatars.githubusercontent.com/u/3833140?v=4)](https://github.com/craiglondon "craiglondon (1 commits)")[![cshehadi](https://avatars.githubusercontent.com/u/639996?v=4)](https://github.com/cshehadi "cshehadi (1 commits)")[![purevirtual](https://avatars.githubusercontent.com/u/1276840?v=4)](https://github.com/purevirtual "purevirtual (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")[![sdlins](https://avatars.githubusercontent.com/u/412490?v=4)](https://github.com/sdlins "sdlins (1 commits)")[![squio](https://avatars.githubusercontent.com/u/169410?v=4)](https://github.com/squio "squio (1 commits)")[![stupidusername](https://avatars.githubusercontent.com/u/3828886?v=4)](https://github.com/stupidusername "stupidusername (1 commits)")[![XZzYassin](https://avatars.githubusercontent.com/u/4236495?v=4)](https://github.com/XZzYassin "XZzYassin (1 commits)")

---

Tags

validatoryii2validatorvalidationyii2at least

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codeonyii-yii2-at-least-validator/health.svg)

```
[![Health](https://phpackages.com/badges/codeonyii-yii2-at-least-validator/health.svg)](https://phpackages.com/packages/codeonyii-yii2-at-least-validator)
```

###  Alternatives

[paulzi/yii2-json-behavior

Yii2 json attribute behavior

76528.6k3](/packages/paulzi-yii2-json-behavior)[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)[dstotijn/yii2-json-schema-validator

A Yii2 extension that provides a validator class for JSON Schema validation.

1730.7k](/packages/dstotijn-yii2-json-schema-validator)

PHPackages © 2026

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