Home php教程 php手册 Yii2 core validator

Yii2 core validator

Aug 25, 2016 am 10:20 AM

Core Validators

Yii provides a series of commonly used core validators, mainly existing under the yiivalidators namespace. To avoid using lengthy class names, you can directly specify the corresponding core validator by nickname. For example, you can use the nickname 'required' to refer to the yiivalidatorsRequiredValidator class, such as:

<span style="color: #008080;">1</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> rules()
</span><span style="color: #008080;">2</span> <span style="color: #000000;">{
</span><span style="color: #008080;">3</span>     <span style="color: #0000ff;">return</span><span style="color: #000000;"> [
</span><span style="color: #008080;">4</span>         [['email', 'password'], 'required'],
<span style="color: #008080;">5</span> <span style="color: #000000;">    ];
</span><span style="color: #008080;">6</span> }
Copy after login

yiivalidatorsValidator::builtInValidators attribute declares all supported validator nicknames.

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #800080;">$builtInValidators</span> =<span style="color: #000000;"> [
        </span>'boolean' => 'yii\validators\BooleanValidator',
        'captcha' => 'yii\captcha\CaptchaValidator',
        'compare' => 'yii\validators\CompareValidator',
        'date' => 'yii\validators\DateValidator',
        'default' => 'yii\validators\DefaultValueValidator',
        'double' => 'yii\validators\NumberValidator',
        'each' => 'yii\validators\EachValidator',
        'email' => 'yii\validators\EmailValidator',
        'exist' => 'yii\validators\ExistValidator',
        'file' => 'yii\validators\FileValidator',
        'filter' => 'yii\validators\FilterValidator',
        'image' => 'yii\validators\ImageValidator',
        'in' => 'yii\validators\RangeValidator',
        'integer' =><span style="color: #000000;"> [
            </span>'class' => 'yii\validators\NumberValidator',
            'integerOnly' => <span style="color: #0000ff;">true</span>,<span style="color: #000000;">
        ]</span>,
        'match' => 'yii\validators\RegularExpressionValidator',
        'number' => 'yii\validators\NumberValidator',
        'required' => 'yii\validators\RequiredValidator',
        'safe' => 'yii\validators\SafeValidator',
        'string' => 'yii\validators\StringValidator',
        'trim' =><span style="color: #000000;"> [
            </span>'class' => 'yii\validators\FilterValidator',
            'filter' => 'trim',
            'skipOnArray' => <span style="color: #0000ff;">true</span>,<span style="color: #000000;">
        ]</span>,
        'unique' => 'yii\validators\UniqueValidator',
        'url' => 'yii\validators\UrlValidator',
        'ip' => 'yii\validators\IpValidator',<span style="color: #000000;">
    ];</span>
Copy after login

The main usage and properties of each validator are introduced in detail below.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)