问题:Input框中如果只能需要输入Id,也就是数字型字符串,需要进行验证。

解决办法

对其进行实时正则验证,

/^[1-9]\d*$/

  

<Form.Item label='ID' >
     {
        getFieldDecorator('id', {
             rules:[{
                 required:false,
                 pattern: new RegExp(/^[1-9]\d*$/, "g"),
                 message: '请输入正确的ID'
             }],
             getValueFromEvent: (event) => {
                 return event.target.value.replace(/\D/g,'')
             },
             initialValue:''
        })(<Input />)
     }
 </Form.Item>

  

这样的操作就是输入框只能输入数字,输入字符是不被允许的,也就是输入不进去字符,从前端确保提交数据格式的正确性

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案