FormItem 表单验证类
string
错误信息
Array.<(string|RegExp)>
验证字段匹配项
Object
规则对象
string
自定义验证函数
Object
验证规则对象
number
验证码
object
表单项数据
Kind: global class
Properties
Name | Type | Description |
---|---|---|
ruleItems | Array.<ruleItem> |
验证规则 |
addRuleItem | function |
添加一条验证规则 |
verify | function |
检查表单是否符合规则 |
boolean
ruleItem
FieldCheck
ruleItem
Array.<(checkCode|errMessage)>
errMessage
表单字段验证类
Example
let fieldCheck = new FieldCheck();
fieldCheck.addRuleItem('rule1',['name'],[
{
type: 'string',
minLength: 2,
maxLength: 10,
message: '姓名必须为2-10个字符'
}
]);
fieldCheck.addRuleItem('rule2',['age'],[
{
type: 'number',
min: 18,
max: 100,
message: '年龄必须为18-100岁'
}]);
let errMsg = fieldCheck.verify({
name: 'kindring',
age: 18});
console.log(errMsg);
// null
let errMsg = fieldCheck.verify({
name: 'kindring',
age: 17});
console.log(errMsg);
// 年龄必须为18-100岁
Param | Type | Description |
---|---|---|
[ruleItems] | Array.<ruleItem> |
验证规则数组 |
boolean
判断是否为空
Kind: instance method of FieldCheck
Param |
---|
v |
ruleItem
构建验证规则
Kind: instance method of FieldCheck
Returns: ruleItem
- 验证规则对象
Param | Type | Description |
---|---|---|
checkFields | Array.<(string|RegExp)> |
需要验证的字段 |
ruleArr | Array.<(validatorFunction|checkRule)> |
验证规则 |
FieldCheck
添加一条验证规则
Kind: instance method of FieldCheck
Returns: FieldCheck
- 返回当前对象
Param | Type | Description |
---|---|---|
ruleName | string |
验证规则名,用于区分 |
checkFields | Array.<(string|RegExp)> |
用于匹配字段的字符或者正则数组 |
ruleArr | Array.<(validatorFunction|checkRule)> |
验证规则 |
ruleItem
获取验证规则
Kind: instance method of FieldCheck
Returns: ruleItem
- 验证规则
Param | Type | Description |
---|---|---|
field | string |
字段名 |
Array.<(checkCode|errMessage)>
检查字段是否符合规则
Kind: instance method of FieldCheck
Returns: Array.<(checkCode|errMessage)>
- 错误码或错误信息
Param | Description |
---|---|
field | 字段名 |
value | 字段值 |
errMessage
检查表单是否符合规则
Kind: instance method of FieldCheck
Returns: errMessage
- 错误码或错误信息
Param | Type | Description |
---|---|---|
formObject | Object |
需要检验的表单项 字段:值 |
[isMustMatch] | 是否强制要求匹配规则 |
Kind: global class
boolean
ruleItem
FieldCheck
ruleItem
Array.<(checkCode|errMessage)>
errMessage
表单字段验证类
Example
let fieldCheck = new FieldCheck();
fieldCheck.addRuleItem('rule1',['name'],[
{
type: 'string',
minLength: 2,
maxLength: 10,
message: '姓名必须为2-10个字符'
}
]);
fieldCheck.addRuleItem('rule2',['age'],[
{
type: 'number',
min: 18,
max: 100,
message: '年龄必须为18-100岁'
}]);
let errMsg = fieldCheck.verify({
name: 'kindring',
age: 18});
console.log(errMsg);
// null
let errMsg = fieldCheck.verify({
name: 'kindring',
age: 17});
console.log(errMsg);
// 年龄必须为18-100岁
Param | Type | Description |
---|---|---|
[ruleItems] | Array.<ruleItem> |
验证规则数组 |
boolean
判断是否为空
Kind: instance method of FieldCheck
Param |
---|
v |
ruleItem
构建验证规则
Kind: instance method of FieldCheck
Returns: ruleItem
- 验证规则对象
Param | Type | Description |
---|---|---|
checkFields | Array.<(string|RegExp)> |
需要验证的字段 |
ruleArr | Array.<(validatorFunction|checkRule)> |
验证规则 |
FieldCheck
添加一条验证规则
Kind: instance method of FieldCheck
Returns: FieldCheck
- 返回当前对象
Param | Type | Description |
---|---|---|
ruleName | string |
验证规则名,用于区分 |
checkFields | Array.<(string|RegExp)> |
用于匹配字段的字符或者正则数组 |
ruleArr | Array.<(validatorFunction|checkRule)> |
验证规则 |
ruleItem
获取验证规则
Kind: instance method of FieldCheck
Returns: ruleItem
- 验证规则
Param | Type | Description |
---|---|---|
field | string |
字段名 |
Array.<(checkCode|errMessage)>
检查字段是否符合规则
Kind: instance method of FieldCheck
Returns: Array.<(checkCode|errMessage)>
- 错误码或错误信息
Param | Description |
---|---|
field | 字段名 |
value | 字段值 |
errMessage
检查表单是否符合规则
Kind: instance method of FieldCheck
Returns: errMessage
- 错误码或错误信息
Param | Type | Description |
---|---|---|
formObject | Object |
需要检验的表单项 字段:值 |
[isMustMatch] | 是否强制要求匹配规则 |
FormItem 表单验证类
Kind: global class
表单项
Param | Type | Description |
---|---|---|
object | object |
表单项数据 |
[fieldCheck] | FieldCheck |
字段验证对象 |
[option] | object |
配置项 |
FieldCheck
字段验证对象
Kind: instance property of FormItem
boolean
检查表单项是否符合要求
Kind: instance method of FormItem
Param | Type | Description |
---|---|---|
form | object |
表单对象 |
isMustMatch | 是否必须全部匹配到验证规则 |
string
检查表单项是否符合要求
Kind: static method of FormItem
Returns: string
- errMsg 错误信息
Param | Type | Description |
---|---|---|
object | object |
表单项数据 |
field | string |
字段名 |
formItemData | formItemData |
表单项数据 |
fieldCheck | FieldCheck |
字段验证对象 |
isMustMatchRule | boolean |
表单字段是否必须匹配到验证规则 |
初始化表单项数据
Kind: static method of FormItem
Param | Type | Description |
---|---|---|
formObject | formObject |
表单对象 |
string
错误信息
Kind: global typedef
Array.<(string|RegExp)>
验证字段匹配项
Kind: global typedef
Object
规则对象
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[type] | string |
类型 |
[min] | number |
最小值 |
[max] | number |
最大值 |
[length] | number |
长度 |
[regex] | RegExp |
正则表达式 |
[message] | errMessage |
错误信息 |
[require] | boolean |
是否必须 |
[minLength] | number |
最小长度 |
[maxLength] | number |
最大长度 |
[validator] | validatorFunction |
自定义验证函数 |
string
自定义验证函数
Kind: global typedef
Returns: string
- 返回错误信息或者 null
Param | Type | Description |
---|---|---|
value | any |
需要验证的值 |
Object
验证规则对象
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
checkFields | Array.<string> |
需要验证的字段 |
rules | Array.<(validatorFunction|checkRule)> |
验证规则 |
number
验证码
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
code_pass | 1 |
验证通过 |
code_notPass | 2 |
验证不通过 |
code_notMatch | 3 |
未匹配到验证规则 |
object
表单项数据
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[val] | string |
表单项值 |
[msg] | string |
表单项错误信息 |
[state] | number |
表单项状态 0 通过 1 通过 2 不通过 |
[showText] | string |
表单项显示文本,用于在某些 |
[label] | string |
表单项显示文本 |
[init] | string |
表单项初始值 |
[options] | Array |
表单项枚举值 |
[depend] | string |
依赖字段, 该项存在将使用依赖字段的option中的checkField字段进行匹配验证规则 |
[reCheckField] | string |
该表单项用于匹配规则的字段 |
[disables] | Array |
禁用项 |