Classes | |
| class | ArrayRule |
| class | DateTimeRule |
| class | EmailDnsRule |
| class | EmailFormatRule |
| class | EqualRule |
| class | FilteredPatternsRule |
| class | FilteredWordsRule |
| class | FloatRule |
| class | IntRangeRule |
| class | IntRule |
| class | IpCidrFormatRule |
| class | IpFormatRule |
| class | IpRangeRule |
| class | NoHtmlRule |
| class | NonEmptyRule |
| class | NumericRule |
| class | RegExpRule |
| class | Rule |
| class | StringRangeRule |
| class | UIntRule |
| class | UrlFormatRule |
But at a deeper level, a Validator class is nothing else than a collection of rules, or classes that extend the Rule interface. Implementing Validator classes as a collection of Rule classes allows for better code reusability, since sometimes most of the Validator classes check for similar things and therefore we can reuse most of the Rule classes.
In order to implement your own rule, simply create your own class extending the Rule class and make sure to implement the Rule.Validate() method with your own validation logic. This method should return 'true' if the data complies with the logic of the rule or 'false' if it does not. Additionally, since Rule extends the Validation interface it is also possible to set certain error flags or messages via the private method Validation._setError(). These error codes can be checked by Validator classes or by users of this class via the Validation.getError() method.
See the documentation of the Validator base class on how to use Rule classes in your own validators.