Yii2.0rules verification rules

Source: Internet
Author: User
Tags valid email address
Required: required value verification attribute [[field name], required, requiredValue & gt; required value, message & gt; prompt information]; # Description: alias of CRequiredValidator, ensure that the feature is not empty. required: required value verification attribute

[['Field name'], required, 'requiredvalue '=> 'required value', 'message' => 'Prompt information']; # Description: alias of CRequiredValidator, ensure that the feature is not empty.

Email: email verification

['Email ', 'Email']; # Note: the alias of CEmailValidator ensures that the feature value is a valid email address.

Match: regular expression verification

[['Field name'], match, 'pattern' => 'regular expression', 'message' => 'Prompt information']; [['Field name'], match, 'Not '=> ture, 'pattern' => 'regular expression', 'message' => 'Prompt information'];/* reverse regex */# description: the alias CRegularExpressionValidator ensures that the feature matches a regular expression.

Url: url

['Website', 'URL', 'defaultscheme '=> 'http']; # Note: the alias of CUrlValidator ensures that the feature is a valid path.

Captcha: verification code

['Notificationcode', 'captcha ']; # Note: the alias of CCaptchaValidator ensures that the value of the feature is equal to the verification code displayed by captcha.

Safe: Secure

['description', 'safe'];

Compare: Comparison

['Age', 'compute', 'compute' => 30, 'operator' => '> =']; # Description: compareValue (constant value) -operator (comparison operator) # Description: the alias of CCompareValidator, which ensures that the feature value is equal to another feature or constant.

Default: default value

['Age', 'default', 'value' => null]; # Description: the alias of CDefaultValueValidator. a default value is assigned to the feature.

Exist: exist

['Username', 'exist']; # Description: the alias of CExistValidator. make sure that the attribute value exists in the specified data table field.

File: file

['Primaryimag', 'file', 'extension' => ['PNG ', 'jpg', 'GIF'], 'maxsize' => 1024*1024*1024]; # Note: the alias of CFileValidator ensures that the feature contains the name of an uploaded file.

Filter: filter

[['Username', 'Email '], 'filter', 'filter' => 'trim', 'skiponarray' => true]; # Description: alias of CFilterValidator, use a filter to convert attributes.

In: Range

['Level', 'in', 'range' => [1, 2, 3]; # Description: alias of CRangeValidator, make sure that the feature appears in a reserved value list.

Unique: Uniqueness

['Username', 'Unique'] # Note: the alias of CUniqueValidator ensures that the feature is unique in data table fields.

Integer: integer

['age', 'integer'];

Number: number

['salary', 'number'];

Double: double floating point type

['salary', 'double'];

Date: date

[['from', 'to'], 'date'];

String: string

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

Boolean: whether it is a boolean value.

['Field name', 'boolean', 'truevalue '=> true, 'falsevalue' => false, 'strict' => true]; # Description: alias of CBooleanValidator

Image: whether it is a valid image file

['primaryImage','image', 'extensions' => 'png, jpg,jpeg','minWidth' => 100,'maxWidth' => 1000,'minHeight' => 100,'maxHeight' => 1000,]

If you have any questions, you can leave a message to add them. Mutual learning

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.