PHPYii framework-Table verification rules _ php instances

Source: Internet
Author: User
Yii is a component-based high-performance PHP framework for developing large Web applications. Yii is written in strict OOP and has a complete library reference and comprehensive tutorials. This article will introduce you to the phpyii Framework's form verification rules, if you are interested, learn it together. Yii is a component-based high-performance PHP framework used to develop large-scale 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.

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.