Custom Validators
Explain how to write a synchronous custom validator function matching Angular's ValidatorFn signature.
Angular's built-in validators (Validators.required, Validators.email, Validators.minLength, and so on) cover common cases, but real forms frequently need domain-specific rules — a password matching a policy, a username that can't contain spaces, a date that must be in the future — and a custom validator is simply a function matching the ValidatorFn signature: it receives an AbstractControl and returns either null (valid) or a ValidationErrors object (invalid), where the object's keys become identifiers you can check in the template to show specific error messages.
A custom validator is like a specialized inspector added to an assembly line's existing quality-control checklist — it plugs into the same pass/fail reporting system as every other inspector, just checking for a rule specific to your product.