PHP yii Framework Form validation rules Encyclopedia _php instance

Source: Internet
Author: User
Tags php class php framework yii

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

No more nonsense to say, directly to everyone paste code.

<?php class Contactform extends Cformmodel {public $_id; public $contact;//Contact public $tel//telephone public $fax;//Fax public $zipcode;/zip public $addr;//Address public $mobile; Mobile phone public $email//Mailbox public $website//URL public $qq//qq public $msn//msn Public Function rules () {RET Urn Array (' contacts ', ' required ', ' on ' => ' edit '), ' message ' => ' contact must be filled in. '), array (' touch ', ' length ', ' on ')
      => ' edit ', ' min ' =>2, ' Max ' =>10, ' tooshort ' => ' contact length please control in 2-10 characters. ', ' toolong ' => ' contact length please control in 2-10 characters. ' Array (' Tel ', ' match ', ' pattern ' => '/^ (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' message ' => ' Please enter the correct phone number. '), array (' Fax ' , ' match ', ' pattern ' => '/^ (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' message ' => ' Please 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 ' => ' Please enter the correct mobile number. '), Array ( ' Email ', ' email ', ' on ' => ' edit ', ' message ' => ' mailbox entered incorrectly. '), Array (' zipcode ', ' required', ' on ' => ' edit ', ' message ' => ' postcode must be filled in. '), Array (' ZipCode ', ' numerical ', ' on ' => ' edit ', ' message ' => ' ZIP code is 6 digits. ') , Array (' zipcode ', ' length ', ' on ' => ' edit '), ' min ' =>6, ' Max ' =>6, ' tooshort ' => ' zip code is 6 digits long. ' ' Toolong ' => ' Zip code length is 6 digits. '), Array (' website ', ' url ', ' On ' => ' edit ', ' message ' => ' URL entered incorrectly. '), Array (' QQ ', ' match ', ' pattern ' =&G T '/^[1-9]{1}[0-9]{4,11}$/', ' message ' => ' Please enter the correct QQ number. '), array (' MSN ', ' email ', ' ' On ' => ' edit ', ' note ' => '
  MSN input is incorrect. '); }
}

Full Example:

Public $password 2;//A non-database field, but public $verify is required in view; Mobile phone authentication code public $FJG;
   Forgotten number/** * Map database table name * @return string The associated db tables name<br><br> * Www.shouce.ren
  * * Public Function TableName () {return ' adm_user ';
   /** * Validation Rule * @return Array validation rules for model attributes. * * Public Function rules () {//note:you should only define the rules for those attributes that//would receive U
    Ser inputs. Return Array (//array (' mobile_phone,name,status ', ' required '), Array (' Mobile_phone ', ' unique '),//' message ' =&G T
      ' The phone number already exists! ' Array (' Mobile_phone ', ' match ', ' pattern ' => '/^ (13|15|18) [0-9]{9}$/', ' message ' => ', please enter the correct operator mobile number. '),//array (' C ertificate_id ', ' match ', ' pattern ' => '/(. Jpg|. Gif|. png|\d) $/', ' message ' => ' Please select the certificate image again and the suffix can only be jpg, GIF, PNG format. ', array (' phone ', ' match ', ' pattern ' => '/^ (\d{3}-|\d{4 }-)? (\d{8}|\d{7})? $/', ' message ' => ' Please enter the correct landline number. ', Array (' Fax ', ' Match ', ' pattern ' => '/^ (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' message ' => ' Please enter the correct fax number. '//array (' email_address ') , ' match ', ' pattern ' => '/^[\w-]+ (\.[ \w-]+) *@[\w-]+ (\.[ 
      \w-]+) +$/', ' message ' => ' Please enter the correct mailbox. ', Array (' email_address ', ' email ', ' message ' => ' Please enter the correct mailbox. '),//Verify password and Confirm password Array ("Password2", "compare", "Compareattribute" => "password", "message" => "two times password inconsistency", ' on ' => ' register '), a
      Rray ("Password2", "compare", "Compareattribute" => "password", "message" => "two times password inconsistency", ' on ' => ' Regonter '), Array (' QQ ', ' match ', ' pattern ' => '/^[1-9]{1}[0-9]{4,11}$/', ' message ' => ' Please enter the correct QQ number. '), Array (' Type,certificat E_id,company_type, nationality,yyzz_id, status,level,create_by_id, Create_time,update_time ', ' numerical ', ' Integeronly ' =>true ', Array (' Verify ', ' Numerical ', ' message ' => ' Authentication Code incorrect ', ' integeronly ' =>true), Array (' Name,user_type,tuijianren ', ' length ', ' Max ' =>20, Array (' password ', ' length ', ' Max ' =>100), ArraY (' email_address,business ', ' length ', ' Max ' =>50), Array (' Communication_address,money, Yhzh,yhmc,industry, Compan Y, Register_address,yhdh,shangbiao,zhuanli,gongshang ', ' length ', ' Max ' =>255, Array (' role_id ', ' Default ', ' Setone Mpty ' =>true, ' value ' =>10), array (' Shangbiao ', ' Default ', ' Setonempty ' =>true ', ' value ' => ' 0,0 '), array (' Zhuanli ', ' Default ', ' Setonempty ' =>true, ' value ' => ' 0,0 '), Array (' Gongshang ', ' Default ', ' Setonempty ' =>
      True, ' value ' => ' 0,0 '), Array (' Password ', ' Default ', ' Setonempty ' =>true, ' value ' => ' 123456 '),/* 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 ',//' m     Axsize ' =>1024 * 1024 *,//10MB//' Toolarge ' => ' file size cannot exceed 10m! ',//' message ' => ' please upload the certificate image first. '// ),//the following RulE is used by search ().
      @todo Please remove those attributes that should is 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_address, certificate, status, create_by_id, Create_time, Update_time ', ' safe ', ' on ' => '
  Search ");
    * * * Phone Verification Code checksum/public Function checkverify ($attribute, $params) {$model =new Mess (); $d _title = $model->find (Array (' condition ' => ' Suij=:suij and Tel=:tel and Type>:type ', ' Params ' =>array (': Suij ' => $this->verify, ': Tel ' => $this->mobile_phone, ': Type ' =>0, ': Time ' => (
    Time () -3600)), ' Select ' =>array (' id ')); $d _title = $model->findbyattributes (the ' Suij ' => $this->verify, ' tel ' => $this->mobile_phone),
    Array (' SELECT ' =>array (' id ')); if ($d _title[' id ']<1 {$this->adderror (' Verify ', ' The authentication code is incorrect.
    "); else {if ($this->password = = $this->password2) {$model->updateall (Array (' type ' =&gt
      0), Array (' condition ' => ' suij=:sj ', ' params ' =>array (': SJ ' => $this->verify))); }
    }
  }

The above code is about the PHP yii framework of the form validation rules encyclopedia full of content, I hope you like.

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.