Yii rules Common rule Example _php instance

Source: Internet
Author: User
Tags rar smarty template yii

This article describes the common rules for yii rules. Share to everyone for your reference, specific as follows:

The Public Function rules () {return array (//) must be filled in array (' email, username, Password,agree,verifypassword,verifycode ', ' required '),//Check whether user name repeats array (' email ', ' unique ', ' message ' => ' username already occupied '),//user enters maximum character limit array (' Email, US Ername ', ' length ', ' Max ' =>64,//limit user minimum length and maximum length array (' username ', ' length ', ' Max ' =>7, ' min ' =>2, ' toolong ' = > ' username please input length of 4-14 characters ', ' tooshort ' => ' username please input length of 2-7 words '),//Limit password minimum length and maximum length array (' Password ', ' length ', ' Max ' =>22 , ' min ' =>6, ' toolong ' => ' password please enter a length of 6-22 characters ', ' tooshort ' => ' password please enter the length of 6-22 characters '),//To determine whether the user entered the mail array (' email ', ' E Mail ', ' message ' => ' mailbox format error ')//Check whether the password entered by the user is the same array (' VerifyPassword ', ' compare ', ' compareattribute ' => ') passwo Rd ', ' message ' => ' Please re-enter the Confirmation password ')//Check whether the user agrees to the terms of the agreement (' agree ', ' required ', ' Requiredvalue ' =>true, ' => ')
    Please confirm whether you agree to the terms of the Privacy Agreement "),//Determine if it is a date format array (' Created ', ' Date ', ' Format ' => ' Yyyy/mm/dd/hh:mm:ss '),//Determine whether to include the characters entered Array (' Superuser ', ' in ', ' Range ' => array (0, 1)),//Regular Validator: Array (' name ', ' match ', ' pattern ' => '/^[a-z0-9\-_]+$/'),//Digital validator: AR Ray (' id ', ' numerical ', ' min ' =>1, ' Max ' =>10, ' integeronly ' =>true),//type validation integer,float,string,array,date, Time,datetime Array (' Created ', ' type ', ' datetime '),//File verification: Array (' filename ', ' file ', ' AllowEmpty ' =>true, '
        Types ' => ' zip, rar, xls, PDF, ppt ', ' toolarge ' => ' picture not exceeding 800K '), array (' URL ', ' file ',///defined as file type ' AllowEmpty ' =>true, ' types ' => ' jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx ',//upload file type ' max Size ' =>1024*1024*10,//upload sizes limit, note not php.ini upload file size ' toolarge ' => ' file is larger than 10M, upload failed! Please upload a file less than 10M!
'
    ),
 }); $news = new News (' Search ');

 Search Association Rules

Turn from: Small Talk blog http://www.tantengvip.com/2015/05/yii-rules/

More about Yii related content readers can view the site topics: "Yii framework Introduction and common skills Summary", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming Program", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips

I hope this article will help you with the PHP program design based on the YII framework.

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.