Describes a function that checks whether a given value is valid.
Should return true if valid, false or ValidationParameters otherwise.
The result may also be returned as a promise if async logic is required (e.g. to make a rest call that checks whether a username is available).
Running expensive operations at a high frequency is probably not a good idea though.
IMPORTANT: validators should only check one thing and be tolerant of issues outside their scope.
For example, consider validating an e-mail field with the rule { email }.
You don't want to show an error when the field is not filled in.
Even if the field is mandatory, you want to show a different error for that.
For this reason, the email validator for example also considers all non-string and empty values as valid.
Describes a function that checks whether a given value is valid.
Should return true if valid, false or ValidationParameters otherwise. The result may also be returned as a promise if async logic is required (e.g. to make a rest call that checks whether a username is available). Running expensive operations at a high frequency is probably not a good idea though.
IMPORTANT: validators should only check one thing and be tolerant of issues outside their scope. For example, consider validating an e-mail field with the rule
{ email }
. You don't want to show an error when the field is not filled in. Even if the field is mandatory, you want to show a different error for that. For this reason, the email validator for example also considers all non-string and empty values as valid.