mobx-form-validator
mobx-form-validate and validator
base onInstallation
npm i mobx-form-validator or yarn add mobx-form-validator
Usage
; @observable @ name=''
Explame
@observable @ userName = '' @observable nickName = '' @observable @ password = '' @observable @ passwordConfirm = '' @observable @ email = '' @observable @ mobilePhone = '' @observable @ age = '' const form = ;console; // userName is requiredconsole; // 请输入1-15位的密码console; // 两次输入的密码不一样console; // 请输入正确的邮箱地址!console; // 请输入正确的手机号码!console; // 年龄介乎0~200之间!console; // false
API
参数 | 说明 | 类型 |
---|---|---|
beforeValidate | 校验前转换,返回要转换的值,如果返回空,则取当前值 | (value) => any |
compare | 与当前对象的某一字段进行全等对比 | string |
custom | 自定义校验,返回错误信息,如果为空则认为校验成功 | (target, targetValue, source) => string | undefined |
lengths | 字符串货数组长度 eg: length:[6,15] | number[] |
max | 最大值 | number |
message | 提示信息 | string |
min | 最小值 | number |
pattern | 正则表达式 | RegExp |
required | 是否必填 | boolean |
type | 数据类型 | Enum Types |
Enum Types
Ascii
Base64
Boolean
CreditCard
Currency
DataURI
Decimal
Email
Float
HexColor
Hexadecimal
IP
Int
JSON
MACAddress
Numeric
URL
UUID
custom
/*** 自定义校验,返回错误信息,如果为空则认为校验成功* @param target 要校验的属性字段* @param targetValue 要检验的值* @param source 要校验的属性所属的对象*/string | undefined;
Change Log
1.3.2
2017-11-08
- add before method rename to beforeValidate
- fix Enum Type
- fix index.d.ts pathc
1.3.0
2017-08-10
- Features
- add compore method