DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Validators

Extbase brings a way to easily tell TYPO3 when a property is valid: by using annotations on class properties, Extbase will find which properties should be validated. To do so, you have to use the @validate annotation inside the phpDoc section of that property.

Of course, you can create and use any validator you want in your configuration object – if it does follow Extbase validator standards.

Example:

/**
 * @var string
 * @validate TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
 */
protected $name;

Tip

To reduce the length of a @validate annotation, you can use the following shortcut naming convention: VendorName.ExtensionName:ValidatorName.

Moreover, a validator from the core of Extbase can be used by writing only its name.

Example

/**
 * @var string
 * @validate NotEmpty
 * @validate EmailAddress
 * @validate MyVendor.MyExtension:Custom
 */
protected $email;

Please be aware that only validators which follow the Extbase validator naming convention can use the shortened notation:

  1. The validator must be in the following namespace of your extension: Vendor\ExtensionName\Validation\Validator;
  2. The validator class must end with Validator.

Oh, by the way, you can use this notation everywhere Extbase parses the @validate annotation, for instance in your controller or model classes. :-)

Parameters

Some validators may require parameters, for instance NumberRangeValidator from Extbase needs the following parameters: minimum and maximum. To do so, use the following notation:

/**
 * @validate NumberRange(minimum: 0, maximum: 100)
 */

Multiple validators

You can attach several validators to the same property. For instance:

/**
 * @var string
 * @validate NotEmpty
 * @validate EmailAddress
 * @validate VendorName.ExtensionName:CustomValidator
 */
protected $email;