Validators

Built-in validator functions for reactive and template-driven forms.

Since Angular 2+ Spec ↗

Syntax

Validators.required | Validators.minLength(n) | Validators.pattern(re)

Parameters

NameTypeRequiredDescription
validator ValidatorFn No A function returning null when valid or an errors map.

Returns

ValidationErrors | null — Validation result merged into control.errors.

Examples

import { FormGroup, FormControl, Validators } from '@angular/forms';

const form = new FormGroup({
  email: new FormControl('', [Validators.required, Validators.email]),
  age: new FormControl(0, [Validators.min(18), Validators.max(120)]),
  code: new FormControl('', Validators.pattern(/^[A-Z]{3}$/)),
});

Notes

Common validators: required, requiredTrue, email, min, max, minLength, maxLength, pattern. Pass one or an array to a control. Combine with custom ValidatorFns; errors appear on control.errors and aggregate up the form tree. Use AsyncValidators for server-side checks.