React - set input max length

3 points
Created by:

In this article, we would like to show you how to set input max length in React.

Quick solution:

<input maxLength={5} />


Practical example

In this example, we use maxLength property to set input max length.

Runnable example:

// ONLINE-RUNNER:browser;

//Note: Uncomment import lines during working with JSX Compiler.
// import React from 'react';

const App = () => {
  return (
      <div>Below you can type max 5 characters:</div>
      <input maxLength={5} />

const root = document.querySelector('#root');
ReactDOM.render(<App />, root);
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂