[PHP]Yii rules常用規則

來源:互聯網
上載者:User
public function rules(){    return array(        //必須填寫        array('email, username, password,agree,verifyPassword,verifyCode', 'required'),        //檢查使用者名稱是否重複        array('email','unique','message'=>'使用者名稱已佔用'),        //使用者輸入最大的字元限制        array('email, username', 'length', 'max'=>64),        //限制使用者最小長度和最大長度        array('username', 'length', 'max'=>7, 'min'=>2, 'tooLong'=>'使用者名稱請輸入長度為4-14個字元', 'tooShort'=>'使用者名稱請輸入長度為2-7個字'),        //限制密碼最小長度和最大長度        array('password', 'length', 'max'=>22, 'min'=>6, 'tooLong'=>'密碼請輸入長度為6-22位字元', 'tooShort'=>'密碼請輸入長度為6-22位字元'),        //判斷使用者輸入的是否是郵件        array('email','email','message'=>'郵箱格式錯誤'),        //檢查使用者輸入的密碼是否是一樣的        array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message'=>'請再輸入確認密碼'),        //檢查使用者是否同意協議條款        array('agree', 'required', 'requiredValue'=>true,'message'=>'請確認是否同意隱私權協議條款'),        //判斷是否是日期格式        array('created', 'date', 'format'=>'yyyy/MM/dd/ HH:mm:ss'),        //判斷是否包含輸入的字元        array('superuser', 'in', 'range' => array(0, 1)),        //正則驗證器:               array('name','match','pattern'=>'/^[a-z0-9\-_]+$/'),        //數字驗證器:                      array('id', 'numerical', 'min'=>1, 'max'=>10, 'integerOnly'=>true),        //類型驗證 integer,float,string,array,date,time,datetime                        array('created', 'type', 'datetime'),        //檔案驗證:               array('filename', 'file', 'allowEmpty'=>true, 'types'=>'zip, rar, xls, pdf, ppt','tooLarge'=>'圖片不要超過800K'),              array('url',                 'file',    //定義為file類型                 'allowEmpty'=>true,                  'types'=>'jpg,png,gif,doc,docx,pdf,xls,xlsx,zip,rar,ppt,pptx',   //上傳檔案的類型                 'maxSize'=>1024*1024*10,    //上傳大小限制,注意不是php.ini中的上傳檔案大小                 'tooLarge'=>'檔案大於10M,上傳失敗!請上傳小於10M的檔案!'             ),  } ); $news= new news('search'); //search關聯規則

以上就介紹了[PHP]Yii rules常用規則,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.