Rules in the YII2

Source: Internet
Author: User

YII2 rules, user name rules, 1, user name can only be the letter 2, the user name is determined to exist 3, the length of the user name 4, the user name cannot be empty
[[' username '], ' match ', ' pattern ' = '/^[a-z]\w*$/i '],
[' username ', ' unique ', ' targetclass ' = ' \common\models\user ', ' message ' = ' user name already exists ',
[' username ', ' string ', ' min ' = 5, ' max ' = 255],

Rules in Yii2, rules for phone numbers
[' Mobile_phone ', ' Required ', ' message ' = ' mobile number cannot be empty '],
[' Mobile_phone ', ' filter ', ' filter ' = ' trim '],
[[' Mobile_phone '], ' match ', ' pattern ' = '/^ (1 ([35][0-9]) | ( 47) | [8] [0126789])) \d{8}$/'],
[' Mobile_phone ', ' unique ', ' targetclass ' = ' \common\models\user ', ' message ' = ' = ' This mobile phone number has alread Y been taken. '],

Rules for passwords, rules for repeating passwords
[' Password ', ' required '],
[' Password ', ' string ', ' min ' = 6],
[' Repassword ', ' compare ', ' compareattribute ' = ' password '],

Rules for mailboxes
[' email ', ' email ', ' message ' = ' Email error ' you entered '],
[' email ', ' unique ', ' targetclass ' = ' \common\models\user ', ' message ' = ' This mailbox has been registered '],

URL Rules

[' Store_logo ', ' url '],


[' start_time ', ' filter ', ' filter ' = ' strtotime '],
[' End_time ', ' filter ', ' filter ' = ' strtotime '],

Default value
[' Status ', ' Default ', ' Value ' =>self::status_check],

Rules in the YII2

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.