Languages
[Edit]
EN

React - set input max length

3 points
Created by:
Adnaan-Robin
724

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

Quick solution:

<input maxLength={5} />

Hint: change 5 to desired input max length.

 

Practical example

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

Runnable example:

// ONLINE-RUNNER:browser;

// Note: Uncomment import lines in your project.
// import React from 'react';

const App = () => {
    return (
        <div>
          <label>
            <span>Type max 5 characters:</span>
            <input maxLength={5} />
          </label>
        </div>
    );
};

const root = document.querySelector('#root');
ReactDOM.render(<App />, root);

Alternative titles

  1. React - set input maxLength
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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.

❤️💻 🙂

Join