Angular 9 References/ Forms

Validator interface

This is the documentation for Angular 9.
You can switch to the latest version Angular 10.

An interface implemented by classes that perform synchronous validation.

Provide a custom validator

The following example implements the Validator interface to create a validator directive with a custom error key.

  selector: '[customValidator]',
  providers: [{provide: NG_VALIDATORS, useExisting: CustomValidatorDirective, multi: true}
class CustomValidatorDirective implements Validator {
  validate(control: AbstractControl): ValidationErrors|null {
    return {'custom': true};
Links & Tutorials



validate(control: AbstractControl): ValidationErrors|null
Method that performs synchronous validation against the provided control. Returns A map of validation errors if validation fails, otherwise null.


registerOnValidatorChange(fn: () => void)?: void
Registers a callback function to call when the validator inputs change.