Redux 表单字段级别验证在 Edge 中不起作用
Redux Form Field Level Validation does not work in Edge
我正在使用此路径中的示例代码 https://redux-form.com/6.6.3/examples/fieldlevelvalidation/ 来验证数字输入
const number = value => value && isNaN(Number(value)) ? 'Must be a number' : undefined
它不会阻止我在 Microsoft Edge 中输入非数字字符。我该如何解决这个问题?
type="number"
将输入转换为数字输入字段。在移动设备上,您会得到只有数字的键盘。所以它更像是一个浏览器的东西。验证只会在输入错误值时阻止提交和显示错误消息。
如果您想在使用 onKeyPress
事件时执行此操作:
const NumberInput = ()=>{
const onKeyPress = (e) => {
if(e.which<48 || e.which>57) {
e.preventDefault()
}
}
return (
<input onKeyPress={onKeyPress} />
)
}
我正在使用此路径中的示例代码 https://redux-form.com/6.6.3/examples/fieldlevelvalidation/ 来验证数字输入
const number = value => value && isNaN(Number(value)) ? 'Must be a number' : undefined
它不会阻止我在 Microsoft Edge 中输入非数字字符。我该如何解决这个问题?
type="number"
将输入转换为数字输入字段。在移动设备上,您会得到只有数字的键盘。所以它更像是一个浏览器的东西。验证只会在输入错误值时阻止提交和显示错误消息。
如果您想在使用 onKeyPress
事件时执行此操作:
const NumberInput = ()=>{
const onKeyPress = (e) => {
if(e.which<48 || e.which>57) {
e.preventDefault()
}
}
return (
<input onKeyPress={onKeyPress} />
)
}