Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Angular forms MaxLengthValidator Directive

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we are going to see what is MaxLengthValidator in Angular 10 and how to use it.
The MaxLengthValidator is used to synchronize a standalone FormControl instance to a form control element

<input maxLength ="number">

Exported from:

  • ReactiveFormsModule
  • FormsModule

Selectors:

  • [maxlength] [formControlName]
  • [maxlength] [formControl]
  • [maxlength] [ngModel]

Approach: 

  • Create the Angular app to be used
  • In app.component.html set maxLength to input so when you are putting data in that input element you cannot exceed the max constantly.
  • Serve the angular app using ng serve to see the output.

 

Example:

app.component.html




<span>GeeksforGeeks</span>
<input type="text" maxlength="12">
<input maxlength="5">


Output:

Reference: https://angular.io/api/forms/MaxLengthValidator

My Personal Notes arrow_drop_up
Last Updated : 03 Jun, 2021
Like Article
Save Article
Similar Reads
Related Tutorials