A free and open-source book on ZF3 for beginners


9.2. Standard Validators Overview

Standard ZF3 validators are provided by the Zend\Validator component 29. Standard validator classes inheritance is shown in figure 9.1. As you can see from the figure, most of them are derived from AbstractValidator base class.

29) Here, we only consider the standard validator classes belonging to the Zend\Validator namespace. But, actually there are more validators that can be considered as standard. We will cover them in further chapters.

Figure 9.1. Validator class inheritance Figure 9.1. Validator class inheritance

Standard validators together with their brief description are listed in table 9.1. As you may notice from the table, they can be roughly divided into several groups:

Table 9.1. Standard validators
Class name Description
EmailAddress Returns boolean true if the value is a valid E-mail address; otherwise returns false.
Hostname Checks whether the value is a valid host name.
Barcode Returns boolean true if and only if the value contains a valid barcode.
CreditCard Returns true if and only if the value follows the common format of credit card number (Luhn algorithm, mod-10 checksum).
Iban Returns true if the value is a valid International Bank Account Number (IBAN); otherwise returns false.
Isbn Returns boolean true if and only if value is a valid International Standard Book Number (ISBN).
Ip Returns true if value is a valid IP address; otherwise returns false.
Uri Returns true if and only if the value is an Uniform Resource Identifier (URI).
Between Returns true if the value lies in certain range; otherwise returns false.
LessThan Returns boolean true if the value is less than certain number; otherwise returns false.
GreaterThan Returns true if and only if value is greater than certain number.
Identical Returns boolean true if the value matches a given token.
Step Checks whether the value is a scalar and a valid step value.
Csrf This validator checks if the provided token matches the one previously generated and stored in a PHP session.
Date Returns true if value is a valid date of the certain format.
DateStep Returns boolean true if a date is within a valid step.
InArray Returns true if value is contained in the given array; otherwise returns false.
Digits Returns boolean true if and only if $value only contains digit characters.
Hex Returns true if and only if value contains only hexadecimal digit characters.
IsInstanceOf Returns true if value is instance of certain class; otherwise returns false.
NotEmpty Returns true if value is not an empty value.
Regex Returns true if value matches against given pattern; otherwise returns false.
StringLength Returns true if the string length lies within given range.
Explode Splits the given value in parts and returns true if all parts pass the given check.
StaticValidator This validator allows to execute another validator without explicitly instantiating it.
Callback This validator allows to execute a custom validation algorithm through the user-provided callback function.
ValidatorChain Wrapper validator allowing to organize several validators in a chain. Attached validators are run in the order in which they were added to the chain (FIFO).

Top