Maximum Length in React TextBox
03 Sep 20262 minutes to read
Enforce a maximum length limit using the maxLength property, which defines the maximum number of characters users can input. By setting this property, you control text length and prevent users from exceeding the specified limit.
// Import the TextBox.
import { TextBoxComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render TextBox.
function App() {
return (
<div className='wrap'>
<TextBoxComponent id="default" placeholder="Enter your comments" maxLength="20"></TextBoxComponent>
</div>
);
}
export default App;
ReactDom.render(<App />, document.getElementById('input-container'));// Import the TextBox.
import { TextBoxComponent } from '@syncfusion/ej2-react-inputs';
import * as React from 'react';
import * as ReactDom from 'react-dom';
// To render TextBox.
function App() {
return (
<div className='wrap'>
<TextBoxComponent id="default" placeholder="Enter your comments" maxLength="20"></TextBoxComponent>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('input-container'));When the user reaches the specified limit, the React TextBox prevents further input, ensuring compliance with the defined character limit. This feature helps maintain data integrity and provides users with clear feedback on the allowed input length.