Custom Validators
Write your own validation constraints.
When Built-ins Are Not Enough
Standard constraints cannot express every rule — a valid coupon code format, a phone number for a region, or a value that must exist in the database. For these you write a custom constraint backed by a validator.
Two Parts of a Custom Constraint
A custom constraint has two pieces:
- An annotation that you place on fields or parameters
- A ConstraintValidator that contains the actual checking logic