// 自定義手機號校驗規則
const validatePhone = (_, value) => {
const phoneRegex = /^1[3456789]\d{9}$/;
if (!value || phoneRegex.test(value)) {
return Promise.resolve();
}
return Promise.reject(new Error('請輸入有效的手機號碼'));
};
<Form.Item
name="mobile"
label="手機號"
rules={[
{
required: true,
message: '請輸入手機號',
},
{ validator: validatePhone }
]}
>
<Input maxLength={200} placeholder="請輸入手機號" />
</Form.Item>