【发布时间】:2021-05-03 21:07:31
【问题描述】:
我正在使用 react-hook-form 创建一个 4 位数字的输入,这不会让用户输入字母或字符,但它忽略了 maxLength 值。我能够得到一个只允许数字的输入,但我无法限制长度。
这是我的输入:
<input
id="fourNumbers"
required
type="number"
name="fourNumbers"
ref={register({ required: true, pattern: /[0-9]{4}/ })}
placeholder="0000"
maxLength="4"
minLength="4"
/>
【问题讨论】:
标签: javascript reactjs forms react-hook-form