Maximum Length in Angular TextArea
25 Sep 20261 minute to read
Enforce a maximum length limit for text input in the Angular TextArea using the maxLength property. This property defines the maximum number of characters that users can input into the textarea.
By setting the maxLength property, you can control text input length and prevent users from exceeding a specified character limit.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import {TextAreaModule} from '@syncfusion/ej2-angular-inputs'
import { Component } from '@angular/core';
@Component({
imports: [
TextAreaModule
],
standalone: true,
selector: 'app-root',
template: `<div class="wrap">
<div class='textarea'>
<ejs-textarea id="default" placeholder="Enter your comments" maxLength="20"></ejs-textarea>
</div>
</div>`
})
export class AppComponent { }import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
bootstrapApplication(AppComponent).catch((err) => console.error(err));When the user reaches the specified limit, the Angular TextArea 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.