接受输入中的十进制值

时间:2019-06-11 13:32:14

标签: javascript reactjs

我有一个输入字段,当前使用type = number,但是这不允许十进制数字,我确实需要允许用户使用十进制输入,但是我似乎无法使其正常工作,正则表达式可能是解决此问题的方法,因为我需要某种验证。

<FormControl fullWidth style={{ width: '50%' }}>
    <InputLabel htmlFor="estimatedValue">Estimated Value</InputLabel>
    <Input
        type="number"
        id="estimatedValue"
        startAdornment={<InputAdornment position="start">£</InputAdornment>}
    />
</FormControl>

1 个答案:

答案 0 :(得分:3)

要获得预期结果,请使用带有类型编号的步骤作为输入

请在下面的链接中获得MDN的引用

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Allowing_decimal_values

<input type="number" step="0.01">