Detailed description of the YII2.0 rules validation rule collection

Source: Internet
Author: User
This article mainly introduces the detailed Yii2.0 rules validation rule set, has a certain reference value, interested in small partners can refer to.

I have been learning Yii2 recently, so today is also a study notes it!

Required: Mandatory Value validation Property

The code is as follows:

[[' Field name '],required, ' requiredvalue ' = ' required value ', ' message ' = ' message ']; #说明: The alias of the Crequiredvalidator ensures that the attribute is not empty.

Email: Email Verification

The code is as follows:

[' email ', ' email ']; #说明: The alias of Cemailvalidator ensures that the value of the attribute is a valid e-mail address.

Match: Regular validation

[[' Field name '],match, ' pattern ' = ' regular expression ', ' message ' = ' hint message ']; [[' Field name '],match, ' not ' =>ture, ' pattern ' = ' regular expression ', ' message ' = ' hint message ']; /* Regular counter */#说明: Cregularexpressionvalidator alias, ensures that the attribute matches a regular expression.

URL: url

The code is as follows:

[' website ', ' url ', ' defaultscheme ' = ' http ']; #说明: The alias of the Curlvalidator ensures that the attribute is a valid path.

CAPTCHA: Verification Code

The code is as follows:

[' Verificationcode ', ' captcha ']; #说明: The alias of Ccaptchavalidator ensures that the value of the attribute is equal to the verification code shown CAPTCHA.

Safe: Secure

[' Description ', ' safe '];

Compare: Comparison

The code is as follows:

[' Age ', ' compare ', ' comparevalue ' and ' = ', ' operator ' and ' >= ']; #说明: CompareValue (compare constant value)-operator (comparison operator)  #说明: Ccomparevalidator alias, ensuring that the value of the attribute is equal to another attribute or constant.

Default: Defaults

The code is as follows:

[' Age ', ' Default ', ' value ' = null]; #说明: An alias for the cdefaultvaluevalidator that assigns a default value to the attribute.

exist: Presence

The code is as follows:

[' username ', ' exist ']; #说明: Cexistvalidator alias to ensure that the attribute value exists in the specified data table field.

File: Files

The code is as follows:

[' Primaryimage ', ' file ', ' extensions ' = [' png ', ' jpg ', ' gif '], ' maxSize ' + 1024*1024*1024]; #说明: The alias of the Cfilevalidator ensures that the feature contains the name of an uploaded file.

Filter: Filter

The code is as follows:

[[' username ', ' email '], ' filter ', ' filter ' = ' trim ', ' skiponarray ' = true]; #说明: Cfiltervalidator alias, use a filter conversion property.

In: Range

The code is as follows:

[' Level ', ' in ', ' range ' = [1, 2, 3]]; #说明: The alias of Crangevalidator ensures that the feature appears in the list of values for a subscription.

Unique: Uniqueness

The code is as follows:

[' username ', ' unique '] #说明: The alias of Cuniquevalidator ensures that the attribute is unique within the data table field.

Integer: Integers

[' Age ', ' Integer '];

Number: Numeric

[' Salary ', ' number '];

Double: dual-precision floating-point

[' Salary ', ' double '];

Date: Day

[[' From ', ' to '], ' date ';

String: Strings

[' username ', ' string ', ' length ' = [4, 24]];

Boolean: Whether it is a Boolean value

The code is as follows:

[' Field name ', ' Boolean ', ' truevalue ' = ' = ', ' falsevalue ' = False, ' strict ' = true]; #说明: Aliases for Cbooleanvalidator

Image: is a valid picture file

The code is as follows:

[' Primaryimage ', ' image ', ' extensions ' = ' png, jpg,jpeg ', ' minWidth ', ' = ', ' maxWidth ' = +, ' minheight ' = >, ' maxheight ' + 1000,]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.