我有一个简单的登录表单,但type: 'number'
输入项 tn 的验证规则不起作用。即使我输入一个数字,我也会进入'tn' is not a valid number'
控制台。
import React from 'react';
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import './style.css';
export const LoginForm = () => {
const onFinish = (values) => {
console.log('Received values of form: ', values);
};
return (
<Form
name="login_form"
className="login-form"
initialValues={{
remember: true,
}}
onFinish={onFinish}
>
<h3 className="main-label">LOG IN</h3>
<Form.Item
name="tn"
rules={[
{
type: 'number',
required: true,
message: 'Wrong number',
},
]}
>
<Input
prefix={<UserOutlined className="site-form-item-icon" />}
placeholder="Enter your tn"
/>
</Form.Item>
<Form.Item
name="password"
rules={[
{
required: true,
message: 'Please input your password',
},
]}
>
<Input
prefix={<LockOutlined className="site-form-item-icon" />}
type="password"
placeholder="Password"
/>
</Form.Item>
<Form.Item>
<Form.Item name="remember" valuePropName="checked" noStyle>
<Checkbox>Remember me</Checkbox>
</Form.Item>
</Form.Item>
...
);
};
我尝试了其他规则,它们工作正常。数字有什么问题?