Some utils are used for validation
npm i validate-framework-utils --save
import Validator from 'validate-framework-utils'; const validator = new Validator(); const field = { rules: 'required | isEmail | maxLength(32)', messages: 'Can not be empty! | Please enter a valid email address. | Can not exceed {{param}} characters.', value: 'example@example.com', }; // `result` is the verification result // `error` contains the error message const { result, error } = validator.validateByField(field); // ...
The field:
rules
One or more rules (separated by | separated)messages
One or more messages (separated by | separated). {{Value}} is the value, and {{param}} is a parameter of likemaxLength(32)
value
The value to use for validation
Required the validation method begins with required
validator.addMethods({ limitSelect(field, param) { return field.value.length <= param; }, });
- addMethods(methods)
- removeMethods(...names)
- validateByField(field)
- required
- isAbc
- isDate
- isDecimal
- isEmail
- isInteger
- isIp
- isNumeric
- isPhone
- isTel
- isUrl
- maxLength(length)
- minLength(length)
- greaterThan(param)
- lessThan(param)
- greaterThanDate(date)
- lessThanDate(date)