Yii2常用規(guī)則

參數(shù)必填

['email, username, password,agree,verifyPassword,verifyCode', 'required']
'email, username, password,agree,verifyPassword,verifyCode' 為請(qǐng)求字段

檢查字段內(nèi)容是否重復(fù)

['email','unique','message'=>'用戶名已占用']
email為請(qǐng)求字段 會(huì)去數(shù)據(jù)庫(kù)表中查找是否有重復(fù)的字段

現(xiàn)在輸入最大字符

['email, username', 'length', 'max'=>64]
'email, username'請(qǐng)求字段 不能大于64字符

限制用戶最小長(zhǎng)度和最大長(zhǎng)度

['username', 'length', 'max'=>7, 'min'=>2, 'tooLong'=>'用戶名請(qǐng)輸入長(zhǎng)度為4-14個(gè)字符', 'tooShort'=>'用戶名請(qǐng)輸入長(zhǎng)度為2-7個(gè)字']

限制密碼最小長(zhǎng)度和最大長(zhǎng)度

['password', 'length', 'max'=>22, 'min'=>6, 'tooLong'=>'密碼請(qǐng)輸入長(zhǎng)度為6-22位字符', 'tooShort'=>'密碼請(qǐng)輸入長(zhǎng)度為6-22位字符']

輸入的是否是郵件格式

['email','email','message'=>'郵箱格式錯(cuò)誤']
驗(yàn)證輸入的email字段是否為郵件格式,不需要自己?jiǎn)为?dú)寫驗(yàn)證規(guī)則!

檢查用戶輸入的密碼是否是一樣的

['verifyPassword', 'compare', 'compareAttribute'=>'password', 'message'=>'請(qǐng)?jiān)佥斎氪_認(rèn)密碼'],

檢查用戶是否同意協(xié)議條款

['agree', 'required', 'requiredValue'=>true,'message'=>'請(qǐng)確認(rèn)是否同意隱私權(quán)協(xié)議條款']
message 為提示信息

判斷是否是日期格式

['created', 'date', 'format'=>'yyyy/MM/dd/ HH:mm:ss']

判斷是否包含輸入的字符

['superuser', 'in', 'range' => array(0, 1)]
superuser 是否包含 0 和 1

正則驗(yàn)證器

['name','match','pattern'=>'/^[a-z0-9-_]+$/']
name 輸入驗(yàn)證字段 | pattern 正則規(guī)則

數(shù)字驗(yàn)證器

['id', 'numerical', 'min'=>1, 'max'=>10, 'integerOnly'=>true]
id 輸入驗(yàn)證字段 | 驗(yàn)證輸入數(shù)值是否在1和10!

類型驗(yàn)證 integer,float,string,array,date,time,datetime

['created', 'type', 'datetime']
驗(yàn)證整數(shù),浮點(diǎn)型,字符串,數(shù)組,日期,時(shí)間,時(shí)間戳

上傳文件格式驗(yàn)證

['filename', 'file', 'allowEmpty'=>true, 'types'=>'zip, rar, xls, pdf, ppt','tooLarge'=>'圖片不要超過(guò)800K']
filename 字段 | types 限定的格式

您最近使用了:

收藏 菜單 QQ