yii2-validation-filters This extension provides a validation filters with javascript support

  1. Installation
  2. Usage
  3. Resources

Installation

composer require --prefer-dist cetver/yii2-validation-filters

Usage

trim
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\TrimValidator::className(),
            'characterMask' => ' ' // optional, default value is " \t\n\r\0\x0B"
        ],
    ];
}
ltrim
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\LeftTrimValidator::className(),
            'characterMask' => ' ' // optional, default value is " \t\n\r\0\x0B"
        ],
    ];
}
rtrim
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\RightTrimValidator::className(),
            'characterMask' => ' ' // optional, default value is " \t\n\r\0\x0B"
        ],
    ];
}
ucfirst
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteUpperCharacterFirstValidator::className(),
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}
lcfirst
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteLowerCharacterFirstValidator::className(),
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}
strtoupper
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteConvertCaseValidator::className(),
            'mode' => MB_CASE_UPPER,
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}
strtolower
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteConvertCaseValidator::className(),
            'mode' => MB_CASE_LOWER,
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}
ucwords
public function rules()
{
    /**
    * NOTE:
    * ucwords('HELLO WORLD'); // HELLO WORLD
    * mb_convert_case('HELLO WORLD', MB_CASE_TITLE); // Hello World
    */
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteConvertCaseValidator::className(),
            'mode' => MB_CASE_TITLE,
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}
mb_convert_case
public function rules()
{
    return [
        [
            'attribute',
            \cetver\ValidationFilters\validators\MultibyteConvertCaseValidator::className(),
            /**
             * MB_CASE_UPPER - converts the attribute value uppercase.
             * MB_CASE_LOWER - converts the attribute value lowercase.
             * MB_CASE_TITLE - converts the first character of each word of the attribute value capitalized.
             */
            'mode' => MB_CASE_UPPER,
            'encoding' => 'UTF-8' // optional, default value is mb_internal_encoding()
        ],
    ];
}

Resources

https://github.com/cetver/yii2-validation-filters

1 0
1 follower
66 downloads
Yii Version: 2.0
License: BSD-2-Clause
Category: Validation
Developed by: c3tv3r
Created on: May 30, 2017
Last updated: a year ago

Downloads

show all

Related Extensions