1.type:int
- max ----最大值
- min ----最小值
{type:"int",max:30,min:1}
2.type:number
- max ----最大值
- min ----最小值
{type:"number",max:30,min:1}
3.type:date
- 該date類型要匹配YYYY-MM-DD類型的日期字符串。
{type:"date"}
4.type:dateTime
- 該dateTime類型要匹配YYYY-MM-DD HH:mm:ss類型的日期字符串。
{type:"dateTime"}
5.type:id
該id類型要匹配/^\d+$/類型的日期字符串。
{type:"id"}
6.type:boolean
{type:"boolean"}
7.type:string
- allowEmpty ----允許空字符串
- required ----必填字段
- format ----RegExp檢查字符串的格式
- max ----字符串的最大長度
- min ----字符串的最小長度
- trim ----檢查前修剪字符串,默認(rèn)為false
{type:"string",allowEmpty:false,required:true,format:"正則",max:30,min:1,trim:false}
8.type:email
該email類型要符合RFC 5322的電子郵件地址。
- allowEmpty ----允許為空字符串,默認(rèn)為false
{type:"email",allowEmpty:false}
9.type:password
該password類型要匹配/^$/類型字符串。
- compare ----比較字段以檢查是否相等,默認(rèn)為null,不檢查。
- max ----密碼的最大長度
- min ----密碼的最小長度,默認(rèn)為6
{type:"password",compare:"compare value",max:"30",min:"1"}
10.type:url
該url類型要匹配網(wǎng)頁URL。
{type:"url"}
11.type:enum
如果type為enum,則需要附加規(guī)則:
- values ---- 數(shù)據(jù)數(shù)組value 必須是其中的一個(gè),此規(guī)則時(shí)必需的
{type:"enum",values:[1,"Tab"]}
12.type:object
如果type為object,則有一個(gè)附加規(guī)則:
- rule ---- 驗(yàn)證對(duì)象屬性的對(duì)象
{type:"object",rule:{}}
13.type:array
如果type為array,則有四個(gè)規(guī)則:
- itemType ---- 此數(shù)組中每個(gè)項(xiàng)目的類型
- rule ---- 驗(yàn)證數(shù)組項(xiàng)目的對(duì)象,僅適用于
itemType - max ---- 數(shù)組的最大長度
- min ---- 陣列的最小長度
{type:"array",itemType:"string",rule:{},max:10,min:1}
縮寫
'int' => {type: 'int', required: true}
'int?' => {type: 'int', required: false }
'integer' => {type: 'integer', required: true}
'number' => {type: 'number', required: true}
'date' => {type: 'date', required: true}
'dateTime' => {type: 'dateTime', required: true}
'id' => {type: 'id', required: true}
'boolean' => {type: 'boolean', required: true}
'bool' => {type: 'bool', required: true}
'string' => {type: 'string', required: true, allowEmpty: false}
'string?' => {type: 'string', required: false, allowEmpty: true}
'email' => {type: 'email', required: true, allowEmpty: false, format: EMAIL_RE}
'password' => {type: 'password', required: true, allowEmpty: false, format: PASSWORD_RE, min: 6}
'object' => {type: 'object', required: true}
'array' => {type: 'array', required: true}
[1, 2] => {type: 'enum', values: [1, 2]}
/\d+/ => {type: 'string', required: true, allowEmpty: false, format: /\d+/}