#1. Validate EmailAddress on the Form
I have a backend form class with an emailAddress
property that has validation logic so that I can
Encapsulate the validation logic into a reusable class. These classes are usually called specifications, validators or rules and are part of the domain.
There are multiple ways of doing this, here is an approach that I use:
Specification
that provides a bool IsSatisifed()
method. EmailWellformedSpec
.If you want to combine multiple specs to a larger one, the Specification Pattern is a good approach. Note that you need to pass in the data through the constructor if you use that pattern, but this is not a problem because the specification classes are usually simple.