版权声明:如需转载,请注明出处 https://blog.csdn.net/zr15829039341/article/details/82745239
antd from验证input框只能输入数字
问题: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>