# Custom Validator

Your own form rule: returns null when valid or an error object when not.

## What is **Custom Validator**?

A **custom validator** is your own form rule: a function that returns `null` when the value is fine or an error object when it isn't.

```typescript
export const noSpaces: ValidatorFn = control =>
  control.value?.includes(' ') ? { noSpaces: true } : null;

username = new FormControl('', noSpaces);
```

Level: Freelancer · [More Angular terms at this level](https://www.ask-codey.com/glossary?category=angular&level=4)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/custom-validator
