PHPYii framework form verification rules, yii Framework _ PHP Tutorial

Source: Internet
Author: User
PHPYii framework-a list of form verification rules, yii Framework. PHPYii framework is a complete list of form verification rules. yii Framework Yii is a component-based high-performance PHP framework for developing large Web applications. Yii adopts strict OOP writing and has a complete library of PHP Yii Framework form verification rules. yii Framework

Yii is a component-based high-performance PHP framework for developing large Web applications. Yii is written in strict OOP mode and has complete library references and Comprehensive tutorials.

If you don't talk much about it, you can directly post code to everyone.

<? Phpclass ContactForm extends CFormModel {public $ _ id; public $ contact; // contact public $ tel; // call public $ fax; // fax public $ zipcode; // zip code public $ addr; // address public $ mobile; // mobile phone public $ email; // email public $ website; // URL public $ qq; // QQ public $ msn; // MSN public function rules () {return array ('Contact ', 'required', 'on' => 'edit ', 'message' => 'contact is required. '), array ('Contact', 'length', 'on' => 'edit', 'min' => 2, 'Max' => 10, 'tooshort '=>' contact length must be 2-10 characters long. ', 'toolong' =>' contact length must be 2-10 characters long. '), array ('tel', 'match', 'pattern' =>'/^ (\ d {3}-| \ d {4 }-) (\ d {8} | \ d {7 })? $/', 'Message' =>' enter the correct phone number. '), array ('fax', 'match', 'pattern' =>'/^ (\ d {3}-| \ d {4 }-) (\ d {8} | \ d {7 })? $/', 'Message' =>' enter the correct fax number. '), array ('mobile', 'match ', 'pattern' => '/^ 13 [0-9] {1} [0-9] {8 }$ | 15 [0189] {1} [0-9] {8} $ | 189 [0-9] {8} $ /', 'message' => 'enter the correct mobile phone number. '), array ('email', 'Email ', 'on' => 'edit', 'message' =>' incorrect email address. '), array ('zipcode', 'required', 'on' => 'edit', 'message' => 'ZIP code is required. '), array ('zipcode', 'numerical', 'on' => 'edit', 'message' => 'The zip code is a six-digit number. '), array ('zipcode', 'length', 'on' => 'edit', 'min' => 6, 'Max' => 6, 'tooshort '=>' The ZIP code length is 6 digits. ', 'toolong' =>' The ZIP code length is 6 digits. '), array ('Website', 'URL', 'on' => 'edit', 'message' =>' The url is incorrectly entered. '), array ('QQ', 'match ', 'pattern' => '/^ [1-9] {1} [0-9] {4, 11} $/', 'message' => 'enter the correct QQ number. '), array ('MSN', 'Email ', 'on' => 'edit', 'message' => 'MSN input error. '),);}}

Complete example:

Public $ password2; // non-database field, but public $ verify is required in view; // mobile phone verification code public $ fjg; // forgot the number/*** ing database table name * @ return string the associated database table name

* Www. shouce. ren */public function tableName () {return 'adm _ user';}/*** verification rule * @ return array validation rules for model attributes. */public function rules () {// NOTE: you shoshould only define rules for those attributes that/will receive user inputs. return array (// array ('mobile _ phone, name, status', 'required'), array ('mobile _ phone', 'Unique '), // 'message' => 'this phone number already exists! 'Array ('mobile _ phone', 'match', 'pattern' => '/^ (13 | 15 | 18) [0-9] {9} $ /', 'message' => 'enter the correct mobile phone number. '), // array ('certificate _ id', 'match', 'pattern' =>'/(.jpg |. gif |. png | \ d) $/', 'message' =>' Please reselect the certificate image and suffix can only be jpg, gif, png format. '), array ('phone', 'match', 'pattern' =>'/^ (\ d {3}-| \ d {4 }-)? (\ D {8} | \ d {7 })? $/', 'Message' =>' enter the correct landline number. '), array ('fax', 'match', 'pattern' =>'/^ (\ d {3}-| \ d {4 }-) (\ d {8} | \ d {7 })? $/', 'Message' =>' enter the correct fax number. '), // array ('email _ address', 'match', 'pattern' =>'/^ [\ w-] + (\. [\ w-] +) * @ [\ w-] + (\. [\ w-] +) + $/', 'message' =>' enter the correct email address. '), array ('email _ address', 'Email', 'message' => 'enter the correct email address. '), // verify the password and confirm the password array ("password2", "compare", "compareAttribute" => "password ", "message" => "two different passwords", 'on' => 'register '), array ("password2", "compare ", "compareAttribute" => "password", "message" => "two different passwords", 'on' =>' Regonter '), array ('QQ', 'match ', 'pattern' => '/^ [1-9] {1} [0-9] {4, 11} $/', 'message' => 'enter the correct QQ number. '), array ('Type, certificate_id, company_type, nationality, yyzz_id, status, level, create_by_id, create_time, update_time', 'numerical ', 'integeronly' => true ), array ('verify ', 'numerical', 'message' => 'Incorrect verification code ', 'integeronly' => true), array ('name, user_type, tuijianren ', 'length', 'Max '=> 20), array ('password', 'L Ength ', 'Max' => 100), array ('email _ address, Business', 'length', 'Max '=> 50), array ('communication _ address, money, yhzh, yhmc, industry, company, register_address, yhdh, shangbiao, zhuanli, gongshang ', 'length', 'Max' => 255 ), array ('role _ id', 'default', 'setonempty' => true, 'value' => 10), array ('shangbiao', 'default ', 'setonempty' => true, 'value' => '0, 0'), array ('zhuanlil', 'default', 'setonempty' => true, 'value' => '0, 0'), array ('gongshang ', 'default', 'setonempty' => true, 'value' => '0, 0'), array ('password ', 'default', 'setonempty' => true, 'value' => '000000'),/* verification code */array ('verify ', 'checkverify ', 'on' => 'register '), array ('email _ address', 'checkemail', 'on' => 'regonter '), // array ('certificate _ id', 'file', 'allowempty '=> true, // 'types' => 'jpg, gif, png, doc, txt ', // 'maxsize' => 1024*1024*10, // 10 MB // 'toolarge' => 'large file size The size cannot exceed 10 MB! ', // 'Message' =>' Upload the certificate image first. '//), // The following rule is used by search (). // @ todo Please remove those attributes that shocould not be searched. array ('Id, role_id, name, password, user_type, email_address, tuijianren, shangbiao, company_type, zhuanli, gongshang, money, yhzh, yhmc, yyzz_id, yhdh, type, level, phone, qq, mobile_phone, fax, communication_address, nationality, industry, company, business, register_a Ddress, certificate, status, create_by_id, create_time, update_time ', 'Safe', 'on' => 'Search '),);} /** mobile phone verification code verification */public function checkVerify ($ attribute, $ params) {$ model = new Mess (); $ d_title = $ model-> find (array ('condition '=> 'suij =: suij and tel =: tel and type>: type and time>: Time ', 'params' => array (': suij' => $ this-> verify, ': Tel' => $ this-> mobile_phone,': type' => 0, ': time' => (time ()-3600), 'select' => arra Y ('id'); // $ d_title = $ model-> findByAttributes (array ('suij '=> $ this-> verify, 'tel '=> $ this-> mobile_phone), array ('select' => array ('id'); if ($ d_title ['id'] <1) {$ this-> addError ('verify ', "the verification code is incorrect. ");} Else {if ($ this-> password ==$ this-> password2) {$ model-> updateAll (array ('type' => 0 ), array ('condition '=> 'suij =: sj', 'params' => array (': sj' = >$ this-> verify )));}}}

The above code is all about the form verification rules of the PHP Yii Framework. I hope you will like it.

The Yii Framework yii is a component-based high-performance PHP framework for developing large Web applications. Yii adopts strict OOP compiling and has a complete library...

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.