Yii 2.0: yii2-validation-filters

This extension provides a validation filters with javascript support
1 follower

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

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads