EN
React - set input max length
3 points
In this article, we would like to show you how to set input max length in React.
Quick solution:
xxxxxxxxxx
1
<input maxLength={5} />
Hint: change
5
to desired input max length.
In this example, we use maxLength
property to set input max length to 5
characters.
Runnable example:
xxxxxxxxxx
1
// Note: Uncomment import lines in your project.
2
// import React from 'react';
3
4
const App = () => {
5
return (
6
<div>
7
<label>
8
<span>Type max 5 characters:</span>
9
<input maxLength={5} />
10
</label>
11
</div>
12
);
13
};
14
15
const root = document.querySelector('#root');
16
ReactDOM.render(<App />, root);