When to Write Validation Code?

I tend to add validations as part of my approach to TDD. Once I
have a need to restrict values I write a test or tests for it, include
the validation and then move on.

This way it stays out of my way until I need it, and I don’t need to do
all the validations up front, or leave them until the end. They
just become part of the flow.