This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

MaxLengthValidator

npm Package @angular/forms
Module import { MaxLengthValidator } from '@angular/forms';
Source forms/src/directives/validators.ts

Overview

      
      @Directive({
    selector: '[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]',
    providers: [MAX_LENGTH_VALIDATOR],
    host: { '[attr.maxlength]': 'maxlength ? maxlength : null' }
})
class MaxLengthValidator implements Validator, OnChanges {
  maxlength: string
  ngOnChanges(changes: SimpleChanges): void
  validate(c: AbstractControl): ValidationErrors | null
  registerOnValidatorChange(fn: () => void): void
}
    

Selectors

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

Inputs

Description

A directive which installs the MaxLengthValidator for any formControlName,formControl, or control withngModelthat also has amaxlength` attribute.

Members

      
      maxlength: string
    

      
      ngOnChanges(changes: SimpleChanges): void
    

      
      validate(c: AbstractControl): ValidationErrors | null
    

      
      registerOnValidatorChange(fn: () => void): void