<Form.Item label="名字">
{getFieldDecorator('name', {
rules: [
{
required: true,
message: '请输入名字',
},
// 方式一:正则匹配(提示错误,阻止表单提交)
{
pattern: /^[^\s]*$/,
message: '禁止输入空格',
}
],
// 方式二:粗暴点<Input>不允许输入空格(其实是将e.tartget.value转成控件自己的值)
// 这个方法的用途非常强大,还可以结合upload做一些文件上传之后的回调处理
getValueFromEvent: (event) => {
return event.target.value.replace(/\s+/g,"")
},
})(<Input size="large" placeholder="请输入名字" maxLength={20} />)}
</Form.Item>
<TextArea
placeholder="请输入处理备注"
showCount
maxLength={200}
style={{ height: 120, marginBottom: 24 }}
onChange={(e: any) => {
console.log('---onChange-', e.target.value)
console.log('处理后---', e.target.value.replace(/\s+/g, ''))
form.setFieldsValue({
remarks: e.target.value.replace(/\s+/g, ''),
})
}}
/>