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

Validator

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

Interface Overview

      
      interface Validator { 
  validate(c: AbstractControl): ValidationErrors | null
  registerOnValidatorChange(fn: () => void)?: void
}
    

Description

An interface that can be implemented by classes that can act as validators.

Usage

      
      @Directive({
  selector: '[custom-validator]',
  providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}]
})
class CustomValidatorDirective implements Validator {
  validate(c: Control): {[key: string]: any} {
    return {"custom": true};
  }
}
    

Child Interfaces

Members

      
      validate(c: AbstractControl): ValidationErrors | null
    

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