Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thyseus/yii2-word-validator
https://github.com/thyseus/yii2-word-validator
blacklist validator whitelist yii yii2-extension
Last synced: about 6 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/thyseus/yii2-word-validator
- Owner: thyseus
- Created: 2016-08-07T08:00:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T08:24:15.000Z (over 6 years ago)
- Last Synced: 2024-10-24T15:40:14.041Z (12 days ago)
- Topics: blacklist, validator, whitelist, yii, yii2-extension
- Language: PHP
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
Awesome Lists containing this project
README
# ATTENTION:
github has been bought by Microsoft. This repository is orphaned and has been moved to:
https://gitlab.com/thyseus/yii2-word-validator
Thanks a lot for your understanding and blame Microsoft.
Word Validator
==============WordValidator validates that the attribute value has a specific words count and checks this value against whitelist and blacklist.
It is a port of https://github.com/antonCPU/word-validator from Anton Yakushin from Yii 1 to Yii 2.##Requirements
Tested in Yii 2.0.9.
##Installation
composer require thyseus/yii2-word-validator
##Usage
Add the following code to your model class rules() method
~~~
use thyseus\validators\WordValidator;public function rules()
{
return [
//other validators...
array('attributeName', WordValidator::className(), /*add custom rules here*/),
);
}~~~
For example:
~~~
use thyseus\validators\WordValidator;public function rules() {
return [
[['message'], WordValidator::className(),
'min' => 2,
'max' => 5,
'whitelist' => array('please', 'test'),
'blacklist' => array('restricted', 'email.*'), //could be a regular expression
'messages' => array(
'max' => '{attribute} is too long (maximum is {max} words, but now it\'s {length})'
),
];
];
~~~#### Validation rules
- **max** - the attribute should contain less (or equal) words count;
- **min** - minimum words count;
- **exact** - expected only this words count;
- **blacklist** - array of words that should not be in the attribute.
There also could be a regular expression;
- **whitelist** - at least one of these words/expressions must be in the attribute.#### Messages
Any default error message could be overridden using **messages** parameter.
All messages support {attribute} and {length} placeholders. Each validation
method adds it's value to a correspond (the same as a name) placeholder.
For **min** rule a message could be specified as:
~~~
[/*...*/
'messages' => array(
'min' => 'Your {attribute} is now has {length} words. But should be
at least {min}'
),
],
~~~Client side validation is supported.