x-validator 表单校验
const schema = {
type: 'object',
properties: {
username: {
'type': 'string',
'title': '手机号',
'x-validator': [
{
required: true,
message: '请输入用户手机号',
},
{
pattern: /^[0-9]\d*$/g,
message: '手机号格式错误'
}
],
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-component-props': {
placeholder: '请输入用户手机号',
},
},
}
}
自定义函数验证
format 可选择的默认提供的正则
- ‘url’,’email’,’ipv6’, ‘ipv4’,’idcard’,’taodomain’
- ‘qq’,’phone’,’money’, ‘zh’, ‘date’,’zip’ ```javascript import { registerValidateRules } from ‘@formily/core’
registerValidateRules({ custom_format: /^\d+$/, // 只能是正则表达式 custom(value) { return value > 100 ? ‘error’ : ‘’ }, }) ```