PHPackages                             kartik-v/yii2-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. [Mail &amp; Notifications](/categories/mail)
4. /
5. kartik-v/yii2-validators

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

kartik-v/yii2-validators
========================

Enhanced Yii2 model validator components / utilities for Yii2 Framework

v1.0.3(6y ago)21137.9k↓11.8%7[1 PRs](https://github.com/kartik-v/yii2-validators/pulls)BSD-3-ClausePHP

Since Aug 1Pushed 6y ago3 watchersCompare

[ Source](https://github.com/kartik-v/yii2-validators)[ Packagist](https://packagist.org/packages/kartik-v/yii2-validators)[ Docs](https://github.com/kartik-v/yii2-email-validator)[ RSS](/packages/kartik-v-yii2-validators/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

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

[](#yii2-validators)

[![Stable Version](https://camo.githubusercontent.com/e268ddf955840b3ad679d495dd61afcf022f24400ec98f097e386b556105f14c/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f762f737461626c65)](https://packagist.org/packages/kartik-v/yii2-validators)[![Unstable Version](https://camo.githubusercontent.com/1b408b17877fe9ada526f0cfbf6449bab97ccf30f410c7858837db8d0a71b666/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f762f756e737461626c65)](https://packagist.org/packages/kartik-v/yii2-validators)[![License](https://camo.githubusercontent.com/19f6f506ecb4269723ba35cdea1c2d00d00d5f79632ee863a03e16d6abea428b/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f6c6963656e7365)](https://packagist.org/packages/kartik-v/yii2-validators)[![Total Downloads](https://camo.githubusercontent.com/c776133c59cc177cf474bd624f39070bf324d0726659ee8fb82d5791fcca42af/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f646f776e6c6f616473)](https://packagist.org/packages/kartik-v/yii2-validators)[![Monthly Downloads](https://camo.githubusercontent.com/58d15827a4cac3ef553165dbad85b0766a905fb4d9332cc23be7361f012c0177/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f642f6d6f6e74686c79)](https://packagist.org/packages/kartik-v/yii2-validators)[![Daily Downloads](https://camo.githubusercontent.com/db6b7350bbedde3c94cc38b91b4898699e7015a2eb8c83fa31d79fbea334c5bc/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d76616c696461746f72732f642f6461696c79)](https://packagist.org/packages/kartik-v/yii2-validators)

This extension adds new model validator components for Yii2 frameworkor and/or enhances existing Yii2 model validators.

The `EmailValidator` extends the [yii\\validators\\EmailValidator](https://www.yiiframework.com/doc/api/2.0/yii-validators-emailvalidator)component to support multiple email inputs for Yii2 framework. In addition this validator allows setting the `multiple` property and setting the `min` and `max` number of email addresses allowed. This is useful for adding validation rules to your attributes in the model and also adds enhanced client validation support for ActiveForm inputs at runtime via Javascript.

The `PhoneValidator` extends the [yii\\validators\\Validator](https://www.yiiframework.com/doc/api/2.0/yii-validators-validator) component using [libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) based on Google's [libphonenumber](https://github.com/googlei18n/libphonenumber) library.

The `CardValidator` extends the [yii\\validators\\Validator](https://www.yiiframework.com/doc/api/2.0/yii-validators-validator) component. It validates standard debit and credit card number inputs using Luhn's checksum validation. It also helps auto detect the card types and additionally validating the card holder name, expiry date and CVV entered.

The `JsonValidator` extends the [yii\\validators\\Validator](https://www.yiiframework.com/doc/api/2.0/yii-validators-validator) component. It validates JSON input in text area fields. The validator also helps to overwrite the JSON input as a pretty format via `prettify` setting. It includes both server and client validations.

Demo
----

[](#demo)

You can see detailed [documentation and demos](http://demos.krajee.com/validators) on usage of this extension.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

> NOTE: Check the [composer.json](https://github.com/kartik-v/yii2-validators/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.

Either run

```
$ php composer.phar require kartik-v/yii2-validators "@dev"

```

or add

```
"kartik-v/yii2-validators": "@dev"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### EmailValidator

[](#emailvalidator)

This class extends the `yii\validators\EmailValidator` class to offer multiple email validation support. The `EmailValidator` class can be easily used via the alias `k-email` in your model validation rules. For example in your model you can use this as shown below:

```
use yii\db\ActiveRecord;

class EmailModel extends ActiveRecord {
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
            [['to', 'cc', 'bcc'], 'k-email', 'allowName' => true, 'enableIDN' => true, 'max' => 5],
        ];
    }
}
```

In your view where you render the model inputs with ActiveForm - you may set `enableClientValidation` to control whether you need client side validation.

```
// views/email/send.php

use yii\widgets\ActiveForm;

$form = ActiveForm::begin(['enableClientValidation' => true]);
echo $form->field($model, 'to')->textInput();
echo $form->field($model, 'cc')->textInput();
echo $form->field($model, 'bcc')->textInput();
// other fields
ActiveForm::end();
```

### PhoneValidator

[](#phonevalidator)

This class extends the `yii\validators\Validator` class to validate phone numbers using [libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) based on Google's [libphonenumber](https://github.com/googlei18n/libphonenumber) library. The `PhoneValidator` class can be easily used via the alias `k-phone` in your model validation rules. For example in your model you can use this as shown below:

```
use yii\db\ActiveRecord;

class ContactModel extends ActiveRecord {
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
            [['phone1'], 'k-phone', 'countryValue' => 'US'],
            [['phone2'], 'k-phone', 'countryAttribute' => 'country', 'applyFormat' => false],
        ];
    }
}
```

### CardValidator

[](#cardvalidator)

The `CardValidator` extends the [yii\\validators\\Validator](https://www.yiiframework.com/doc/api/2.0/yii-validators-validator) component. It validates standard debit and credit card number inputs using Luhn's checksum validation. It also helps auto detect the card types and additionally validating the card holder name, expiry date and CVV entered. The `CardValidator` class can be easily used via the alias `k-card` in your model validation rules. For example in your model you can use this as shown below:

```
use yii\db\ActiveRecord;

class PaymentModel extends ActiveRecord {
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
            [
                ['card_number'],
                'k-card',
                'typeAttribute' => 'card_type',
                'holderAttribute' => 'holderName',
                'expiryYearAttribute' => 'expiryYear',
                'expiryMonthAttribute' => 'expiryMonth',
                'cvvAttribute' => 'cvv',
            ],
        ];
    }
}
```

### JsonValidator

[](#jsonvalidator)

The `JsonValidator` extends the [yii\\validators\\Validator](https://www.yiiframework.com/doc/api/2.0/yii-validators-validator) component. It validates JSON input in text area fields. The validator also helps to overwrite the JSON input as a pretty format via `prettify` setting. It includes both server and client validations. The `JsonValidator` class can be easily used via the alias `k-json` in your model validation rules. For example in your model you can use this as shown below:

```
use yii\db\ActiveRecord;

class ProductModel extends ActiveRecord {
    /**
     * @return array the validation rules.
     */
    public function rules()
    {
        return [
            [
                ['products_list_json'],
                'k-json',
                'prettify' => true, // set this to false if you do not wish to prettify the json input
            ],
        ];
    }
}
```

License
-------

[](#license)

**yii2-validators** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 74.2% 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 ~128 days

Total

4

Last Release

2461d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3592619?v=4)[Kartik Visweswaran](/maintainers/kartik-v)[@kartik-v](https://github.com/kartik-v)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (23 commits)")[![wiperawa](https://avatars.githubusercontent.com/u/14181470?v=4)](https://github.com/wiperawa "wiperawa (4 commits)")[![vuongxuongminh](https://avatars.githubusercontent.com/u/38932626?v=4)](https://github.com/vuongxuongminh "vuongxuongminh (2 commits)")[![SereiaMaster](https://avatars.githubusercontent.com/u/22714312?v=4)](https://github.com/SereiaMaster "SereiaMaster (1 commits)")[![Stern87](https://avatars.githubusercontent.com/u/13180074?v=4)](https://github.com/Stern87 "Stern87 (1 commits)")

---

Tags

validatorvalidationemailmodeljqueryyii2multiplekrajee

### Embed Badge

![Health badge](/badges/kartik-v-yii2-validators/health.svg)

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

###  Alternatives

[egulias/email-validator

A library for validating emails against several RFCs

11.6k691.3M307](/packages/egulias-email-validator)[kartik-v/yii2-widget-growl

A widget to generate growl based notifications using bootstrap-growl plugin (sub repo split from yii2-widgets)

384.2M14](/packages/kartik-v-yii2-widget-growl)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

87129.2k2](/packages/nterms-yii2-mailqueue)[ashallendesign/laravel-mailboxlayer

A lightweight Laravel package for validating emails using the Mailbox Layer API.

762.0k](/packages/ashallendesign-laravel-mailboxlayer)

PHPackages © 2026

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