參數必填
['email, username, password,agree,verifyPassword,verifyCode', 'required']
'email, username, password,agree,verifyPassword,verifyCode' 為請求字段
檢查字段內容是否重復
['email','unique','message'=>'用戶名已占用']
email為請求字段 會去數據庫表中查找是否有重復的字段
現在輸入最大字符
['email, username', 'length', 'max'=>64]
'email, username'請求字段 不能大于64字符
限制用戶最小長度和最大長度
['username', 'length', 'max'=>7, 'min'=>2, 'tooLong'=>'用戶名請輸入長度為4-14個字符', 'tooShort'=>'用戶名請輸入長度為2-7個字']
限制密碼最小長度和最大長度
['password', 'length', 'max'=>22, 'min'=>6, 'tooLong'=>'密碼請輸入長度為6-22位字符', 'tooShort'=>'密碼請輸入長度為6-22位字符']
輸入的是否是郵件格式
['email','email','message'=>'郵箱格式錯誤']
驗證輸入的email字段是否為郵件格式,不需要自己單獨寫驗證規則!
檢查用戶輸入的密碼是否是一樣的
['verifyPassword', 'compare', 'compareAttribute'=>'password', 'message'=>'請再輸入確認密碼'],
檢查用戶是否同意協議條款
['agree', 'required', 'requiredValue'=>true,'message'=>'請確認是否同意隱私權協議條款']
message 為提示信息
判斷是否是日期格式
['created', 'date', 'format'=>'yyyy/MM/dd/ HH:mm:ss']
判斷是否包含輸入的字符
['superuser', 'in', 'range' => array(0, 1)]
superuser 是否包含 0 和 1
正則驗證器
['name','match','pattern'=>'/^[a-z0-9\-_]+$/']
name 輸入驗證字段 | pattern 正則規則
數字驗證器
['id', 'numerical', 'min'=>1, 'max'=>10, 'integerOnly'=>true]
id 輸入驗證字段 | 驗證輸入數值是否在1和10!
類型驗證 integer,float,string,array,date,time,datetime
['created', 'type', 'datetime']
驗證整數,浮點型,字符串,數組,日期,時間,時間戳
上傳文件格式驗證
['filename', 'file', 'allowEmpty'=>true, 'types'=>'zip, rar, xls, pdf, ppt','tooLarge'=>'圖片不要超過800K']
filename 字段 | types 限定的格式