Home React: input maxlength
Post
Cancel

React: input maxlength

1
2
3
4
5
6
7
8
<input
    onInput={(e) => {
      if (e.currentTarget.value.length > e.currentTarget.maxLength)
        e.currentTarget.value = e.currentTarget.value.slice(0, e.currentTarget.maxLength);
    }}
    type="number"
    maxlength={9}
/>
This post is licensed under CC BY 4.0 by the author.