Advanced Object Validation
With the composable nature of Strickland, it is very easy to perform advanced object validation. If our person object might be null in the input, we could use required
to validate that it isn't null. And since validators are just functions, we could even write a custom validator to ensure that a person named 'Stanford Strickland' must be born in 1925.
In this example, the following will be validated (in this order):
The
person
is not emptyThe
person
props are validated:firstName
is not emptyfirstName
has a length between 2 and 20lastName
is not emptylastName
has a length between 2 and 20birthYear
is between 1900 and 2018
stanfordStricklandBornIn1925
is validated
Here are some notes should anything have been invalid:
If the
person
was empty, neither the object props norstanfordStricklandBornIn1925
would be validatedIf the
firstName
prop was empty, its length would not be validatedIf the
lastName
prop was empty, its length would not be validatedIf the
firstName
,lastName
, orbirthYear
props were invalid,stanfordStricklandBornIn1925
would not be validated
Last updated