18位字母数字校验:
const otherRules = [
{
validator: (a: any, b: any, callback: any) => {
console.log('callback',callback)
if (b) {
if (!/^[A-Za-z0-9]+$/.test(b)) {
callback("只能输入数字、字母");
} else if (b.length === 18 || !b) {
callback();
} else {
callback("必须为18位数字、字母");
}
}
callback()
},
},
];
18位校验:
const otherRules = [
{
validator: (a: any, b: any, callback: any) => {
if (Number(b).toString().length === 18 || !b) {
callback();
} else {
callback('必须为18位数字');
}
},
},
];
input框:
<Form.Item
shouldUpdate={(pre, next) =>
pre.invoice_option !== next.invoice_option ||
pre.customer_type !== next.customer_type
}
noStyle
>
{({ getFieldValue }) =>
<Form.Item
label='纳税人识别码'
name='license_no'
rules={(getFieldValue("invoice_option") === "0" ||
getFieldValue("customer_type") === "1") ? otherRules : [{
required: true,
message: "必填",
}, ...otherRules]}
>
<Input placeholder='请输入纳税人识别码' />
</Form.Item>
}
</Form.Item>