PHPackages                             hgh/yii-input-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. hgh/yii-input-validator

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

hgh/yii-input-validator
=======================

Using this library, You can validate value of any element using rules

1.0.1(6y ago)00MITJavaScript

Since Jul 13Pushed 6y agoCompare

[ Source](https://github.com/H-Gh/yii-input-validator)[ Packagist](https://packagist.org/packages/hgh/yii-input-validator)[ Docs](https://github.com/H-Gh/yii-input-validator)[ RSS](/packages/hgh-yii-input-validator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Yii Input Validator
===================

[](#yii-input-validator)

Using this library you can validate value of `html` `inputs`.

[![License](https://camo.githubusercontent.com/f8b5d47110991d2d526c807cbd4be6419778af9ffef3e21d03a91e35095d652a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f482d47682f7969692d696e7075742d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f8b5d47110991d2d526c807cbd4be6419778af9ffef3e21d03a91e35095d652a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f482d47682f7969692d696e7075742d76616c696461746f722e7376673f7374796c653d666c61742d737175617265) [![Code size](https://camo.githubusercontent.com/9df3a56b535821b4a5b0f32b2e02b718440546db277a7ebefa0f86bcd25d6931/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f482d47682f7969692d696e7075742d76616c696461746f722e7376673f636f6c6f723d726564267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9df3a56b535821b4a5b0f32b2e02b718440546db277a7ebefa0f86bcd25d6931/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f482d47682f7969692d696e7075742d76616c696461746f722e7376673f636f6c6f723d726564267374796c653d666c61742d737175617265)

Usage
-----

[](#usage)

### Register Yii2 Asset

[](#register-yii2-asset)

```
YiiJsEventHandlerAsset::register($this);
```

### Instantiate jQuery Plugin

[](#instantiate-jquery-plugin)

There are two way of instantiate this `jQuery` plugin.

#### Use default attributes

[](#use-default-attributes)

To use default options you have to add two predefined attribute to your `html` element. You put your `rules` into `data-validation-rules`. Separate your `rules` using `space`. Then using `data-validate-on` specify when these `input` should be validate. The values that you can put in `data-validate-on` follows `jQuery` events. Visit [Form events](https://api.jquery.com/category/events/form-events/), [Mouse events](https://api.jquery.com/category/events/mouse-events/) and [keyboard events](https://api.jquery.com/category/events/keyboard-events/) .

```

```

#### Define your custom attributes

[](#define-your-custom-attributes)

In other hand, You can define your custom attributes. For this you have to `instantiate` `inputValidator` plugin.

```
$(document).ready(function () {
    $("[data-custom-validate-on]").inputValidator({
        validateOnAttribute: "data-custom-validate-on",
	validationRulesAttribute: "data-custom-validation-rules",
	validateValueEvent: "customValidateValue"
    });
});
```

Now, you can use these attributes like this:

```

```

***Note:*** Try to use predefined `event` but if you define custom `validateValueEvent`, you have to handle this event yourself. Just predefined `evnet` is handled.

Handle you custom event like this:

```
$(document).on("customValidateValue", function (event) {
    var validator = new Validator(
        // Element which its value will validate
        event.target,
        // Attribute of your element which holds rules for validation
        "data-custom-validation-rules");
    validator.validate();
});
```

Rules
-----

[](#rules)

Some pattern can have custom message. If any `rule` get some attributes, it get attributes as a `json`. ***Note*** : *You can use multi rules. just separate them using `space`.*

- [required](#required)
- [number](#number)
- [ne](#ne)
- [nin](#nin)
- [in](#in)
- [regex](#regex)

### required

[](#required)

##### Description:

[](#description)

This rule, check `length` of `input` value.

##### Predefined message

[](#predefined-message)

```
This field is required.

```

##### Sample

[](#sample)

```

```

### number

[](#number)

##### Description

[](#description-1)

This rule, check if the `input` value is a `number` or not.

##### Predefined message

[](#predefined-message-1)

```
This field should be number.

```

##### sample

[](#sample-1)

```

```

### ne

[](#ne)

##### Description

[](#description-2)

This rule, check if the `input` value is `not equal` to a `value`.

##### Predefined message

[](#predefined-message-2)

```
Invalid value.

```

##### sample

[](#sample-2)

```

```

### nin

[](#nin)

##### Description

[](#description-3)

This rule, check if the `input` value is `not in` in a `list`.

##### Predefined message

[](#predefined-message-3)

```
The value must follow {pattern}

```

##### sample

[](#sample-3)

```

```

### in

[](#in)

##### Description

[](#description-4)

This rule, check if the `input` value is `in` in a `list`.

##### Predefined message

[](#predefined-message-4)

```
The value must follow {pattern}

```

##### sample

[](#sample-4)

```

```

### regex

[](#regex)

##### Description

[](#description-5)

This rule, check if the `input` value match `pattern`.

##### Predefined message

[](#predefined-message-5)

```
Use only allowed characters follows by {pattern}

```

##### sample

[](#sample-5)

```

```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

2537d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7873222f18ced9739dd54f5bcfa13a8d9738496d22b38ff35d9f4b5b84f3269b?d=identicon)[h.gh](/maintainers/h.gh)

---

Top Contributors

[![H-Gh](https://avatars.githubusercontent.com/u/32479577?v=4)](https://github.com/H-Gh "H-Gh (3 commits)")

---

Tags

phpjavascriptjqueryyii2

### Embed Badge

![Health badge](/badges/hgh-yii-input-validator/health.svg)

```
[![Health](https://phpackages.com/badges/hgh-yii-input-validator/health.svg)](https://phpackages.com/packages/hgh-yii-input-validator)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[proengsoft/laravel-jsvalidation

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

1.1k2.3M50](/packages/proengsoft-laravel-jsvalidation)[fedemotta/yii2-widget-datatables

DataTables widget for Yii2

34182.9k1](/packages/fedemotta-yii2-widget-datatables)

PHPackages © 2026

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