Download the PHP package hgh/yii-input-validator without Composer
On this page you can find all versions of the php package hgh/yii-input-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hgh/yii-input-validator
More information about hgh/yii-input-validator
Files in hgh/yii-input-validator
Package yii-input-validator
Short Description Using this library, You can validate value of any element using rules
License MIT
Homepage https://github.com/H-Gh/yii-input-validator
Informations about the package yii-input-validator
Yii Input Validator
Using this library you can validate value of html inputs.
Usage
Register Yii2 Asset
Instantiate jQuery Plugin
There are two way of instantiate this jQuery plugin.
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, Mouse events and keyboard events .
Define your custom attributes
In other hand, You can define your custom attributes. For this you have to instantiate inputValidator plugin.
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:
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
- number
- ne
- nin
- in
- regex
required
Description:
This rule, check length of input value.
Predefined message
This field is required.
Sample
number
Description
This rule, check if the input value is a number or not.
Predefined message
This field should be number.
sample
ne
Description
This rule, check if the input value is not equal to a value.
Predefined message
Invalid value.
sample
nin
Description
This rule, check if the input value is not in in a list.
Predefined message
The value must follow {pattern}
sample
in
Description
This rule, check if the input value is in in a list.
Predefined message
The value must follow {pattern}
sample
regex
Description
This rule, check if the input value match pattern.
Predefined message
Use only allowed characters follows by {pattern}