reactjs - 如何通过 react-bootstrap 验证表单控件以仅使用数值

标签 reactjs validation react-bootstrap

我只需要使用 react-bootstrap 在我的 Form.Control 中输入数值。另外,我需要给控件一个最大长度。

我试过使用 type="number"和 maxLength="10",但它允许我输入超过 10 位数字,并且有一个默认样式适用于带有两个箭头的控件以增加和减少数字,我不想要。

<Form> 
<Form.Group>
<Form.Control
    className="mobileBox"
    required
    name="mobile"
    type="number"
    maxLength="10"
    value={props.mobile}
    onChange={props.onChange}
/>
</Form.Group>
</Form>

最佳答案

您可以通过添加此 CSS 样式来移除用于数字增加和减少的旋转框

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    margin: 0; 
}

关于reactjs - 如何通过 react-bootstrap 验证表单控件以仅使用数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56848369/

相关文章:

javascript - import ES6 两边的括号

javascript - 将 javascript map 代码转换为 React

ruby-on-rails - 非模型的Rails验证

vba - 如何在 VBA 中使用枚举进行验证

javascript - 通过路由 react 传递对象?

javascript - 如何使用 React-bootstrap 进行多输入表单验证?

twitter-bootstrap - 无法提交表单react-bootstrap

javascript - React Native 中未定义函数

javascript - 将鼠标悬停在按钮上时如何打开 material-ui 菜单

typescript - 类验证器使用 createQueryBuilder 意外触发验证