The documentation is a bit spare on how custom rules should be handled in Validator. E.g., I am assuming that if you have multiple custom rules, they are all handled via decision trees in the "custom" configuration object. And if that is true, then I am assuming you have to do the same for the "message" configuration object if you want to have a different message for each custom rule.
However, it is not clear in the documentation how one should send the specific message text.
E.g., let's say we want to have two custom rules.
- One rule checks the "firstname" input field and fails if the value does not include "Tom". On failure, we want the message for that field to be "Please be a Tom".
- The other rule checks the "lastname" input field and fails if the value does not include "Smith". On failure, we want the message for that field to be "Please be a Smith".
Based on what examples I can find in the forums, my first guess at how one would do this looks like the following:
The above code is for illustration and has not been actually tested.
However, I do know that the line
return
'Please be Tom'
;
fails to place any text in the error message.
My hunch is that there is a specific formatting function that must be used. Any hints or leads, here, for what that might be?
TIA