<?phpclass Contactform extends cformmodel{public $_id; public $contact;//Contact public $tel;//Telephone public $fax;//Fax public $zipcode;//Postal code public $ADDR;//Address public $mobi le;//Mobile public $email;//mailbox public $website;//URL public $qq,//QQ public $msn,//MSN Public Function rules () {return Array (' contacts ', ' required ', ' on ' = ' edit ', ' message ' = ' = ' contact must be filled in. '), array (' Contacts ', ' length ', ' on ' = ' = ' edit ', ' min ' =>2, ' Max ' =>10, ' tooshort ' = ' + ' contact length please control in 2-10 characters. ', ' toolong ' = ' Contact length please control at 2-10 characters. ', Array (' Tel ', ' match ', ' pattern ' = '/^ ' (\d{3}-|\d{4}-) (\d{8}|\d{7})? $/', ' Me Ssage ' = ' 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 ' = ' email ' is incorrectly entered. '), Array (' zipcode ', ' required ', ' on ' = ' edit ', ' message ' = ' + ' zip code must be filled in. '), Array (' ZipCode ', ' numerical ', ' on ' = = ' edit ', ' message ' = ' zip ' is 6 digits. '), Array (' zipcode ', ' length ', ' on ' =&G t; ' Edit ', ' min ' =>6, ' Max ' =>6, ' tooshort ' + ' zip code is 6 digits long. ', ' toolong ' = ' + ' ZIP code is 6 digits long. '), Array (' Websit E ', ' url ', ' on ' + ' edit ', ' message ' = ' URL entered incorrectly. '), Array (' QQ ', ' match ', ' pattern ' = '/^[1-9]{1}[0-9]{4,11}$/ ', ' message ' + ' Please enter the correct QQ number. '), array (' MSN ', ' email ', ' on ' = ' edit ', ' message ' = ' MSN input ' is incorrect. '); } }
Complete Example:
Public $password 2;//fields of non-database, but public $verify is required in view;//mobile code public $FJG; Forgot number/** * Map database table name * @return string The associated database table name
* Www.shouce.ren */public function tableName () {return ' Adm_user ';} /** * Validation rules * @return Array validation rules for model attributes. */public function Rules () {//note:you should only define rules for those attributes that//would receive user Inputs.retur N Array (//array (' mobile_phone,name,status ', ' required '), Array (' Mobile_phone ', ' unique '),//' message ' = ' "The mobile number already exists !‘ Array (' Mobile_phone ', ' match ', ' pattern ' = '/^ ' (13|15|18) [0-9]{9}$/', ' message ' = ' = ' Please enter the correct operator's mobile number. '),//array (' certificate_id ', ' match ', ' pattern ' = '/(. Jpg|. Gif|. png|\d) $/', ' message ' = ' Please re-select 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 ' = = ' 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 email. ', array (' email_address ', ' email ', ' message ' = ' = ' Please enter the correct email address. '),//Verify password and Confirm password Array ("Password2", "compare", "compareattribute" = "password", "message" = "two times password Inconsistent", ' on ' = ' Register '), Array ("Password2", "compare", "compareattribute" = "password", "message" = "two times password Inconsistent", ' on ' = ' Regonter '), Array (' QQ ', ' match ', ' pattern ' = '/^[1-9]{1}[0-9]{4,11}$/', ' message ' = ' Please 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 ' = ' Verification 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, 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 (' Zhuanli ', 'Default ', ' Setonempty ' =>true, ' value ' = ' 0,0 '), Array (' Gongshang ', ' Default ', ' Setonempty ' =>true, ' value ' = > ' 0,0 '), Array (' Password ', ' Default ', ' Setonempty ' =>true, ' value ' = ' 123456 '),/* Captcha */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 * 1024x768 *,//10mb//' Toolarge ' + ' file size cannot exceed 10m! ',//' message ' = ' Please upload the certificate image first. ' ),//The following rule is used by search ().//@todo Remove those attributes that should not being 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 '), );} /* * Mobile Verification Code Check */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 ' =>array (' id '));//$d _title = $ Model->findbyattributes (' suij ' = = $this->verify, ' tel ' = + $this->mobile_phone), Array (' SELECT ' = >array (' id '))), if ($d _title[' id ']<1) {$this->adderror (' Verify ', "The captcha is incorrect. ");} Else{if ($this->password = = $this->password2) {$model->updateall (Array (' type ' =>0), array (' condition ' = > ' suij=:sj ', ' params ' =>array (': SJ ' = $this->verify))}}
YII Form Validation rules Daquan