Built-in validators provided by Extbase

This document lists all built-in Extbase validators, along with example usage for each using PHP attributes.

AlphanumericValidator

The AlphanumericValidator checks that a value contains only letters and numbers — no spaces, symbols, or special characters.

This includes letters from many languages, not just A–Z. For example, letters from alphabets like Hebrew, Arabic, Cyrillic, and others are also allowed.

This is useful for fields like usernames or codes where only plain text characters are allowed.

If you want to allow any symbols (like @, #, -) or spaces, use the RegularExpressionValidator instead.

#[Validate(['validator' => 'Alphanumeric'])]
protected string $username;
Copied!

BooleanValidator

The BooleanValidator checks if a value matches a specific boolean value (true or false).

By default, it accepts any boolean value unless the is option is set.

Options:

is

This option enforces that a property explicitly evaluates to either true or false, such as for checkboxes in forms.

Interprets strings 'true', '1', 'false', '0'. Values of other types are converted to boolean directly.

Ensure that a value is a boolean (no strict check, default behavior):

#[Validate(['validator' => 'Boolean'])]
protected $isActive;
Copied!

Require that a value must be true (e.g. checkbox must be checked):

#[Validate(['validator' => 'Boolean', 'options' => ['is' => true]])]
protected bool $termsAccepted;
Copied!

Require that a value must be false:

#[Validate(['validator' => 'Boolean', 'options' => ['is' => false]])]
protected bool $isBlocked;
Copied!

CollectionValidator

The CollectionValidator is a built-in Extbase validator for validating arrays or collections, such as arrays of DTOs or ObjectStorage<T> elements.

It allows you to apply a single validation to each individual item in a collection. The validation is recursive: every item is passed through the validator you specify.

elementValidator
The name or class of a validator that should be applied to each item in the collection (e.g. 'NotEmpty', 'EmailAddress').
elementType
The class name of the collection's element type. All registered validators for that type will be applied to each item.

You must provide either elementValidator or elementType.

Use cases:

  • Validating dynamic or repeatable form fields (e.g. multiple answers)
  • Validating input arrays from multi-select fields or checkboxes
  • Validating each related object in an ObjectStorage property

ConjunctionValidator

The ConjunctionValidator allows you to combine multiple validators into a logical AND. All validators in the conjunction must return valid results for the overall validation to pass.

This validator is typically used internally by Extbase when multiple #[Validate] attributes are defined on a property or when validator conjunctions are configured in the validator resolver.

Behavior:

  • All validators in the conjunction are applied to the value.
  • If any validator fails, the entire validation fails.
  • Errors from all failing validators are combined in the result.

While this validator is often constructed internally, you can also define your own validator combinations manually in the validator resolver or via custom validators.

DateTimeValidator

The DateTimeValidator ensures a value is a valid \DateTimeInterface.

#[Validate(['validator' => 'DateTime'])]
protected mixed $startDate;
Copied!

DisjunctionValidator

The DisjunctionValidator is a composite Extbase validator that allows you to combine multiple validators using a logical OR.

It is the inverse of the ConjunctionValidator: the value is considered valid if at least one of the nested validators succeeds.

Behavior: - All validators are evaluated in order. - Validation stops as soon as one validator passes. - If all validators fail, their errors are merged and returned. - If any validator passes, the result is considered valid.

Use cases:

Use this validator when a value is allowed to match one of multiple conditions. For example: - A field can be either empty or a valid email - A string can be either a number or "N/A" - A value can match one of multiple formats

Usage:

This validator is typically used manually in custom validators or in validator resolver configurations.

EmailAddressValidator

The EmailAddressValidator an email address using method \TYPO3\CMS\Core\Utility\GeneralUtility::validEmail(), which uses the validators defined in $GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'].

It respects

#[Validate(['validator' => 'EmailAddress'])]
protected string $email;
Copied!

FileNameValidator

The FileNameValidator validates, that the given UploadedFile or ObjectStorage with objects of type UploadedFile objects does not contain a PHP executable file by checking the given file extension.

Internally the \TYPO3\CMS\Core\Resource\Security\FileNameValidator is used to validate the file name.

FileSizeValidator

The FileSizeValidator validates, that the given UploadedFile ObjectStorage with objects of type UploadedFile objects do not exceed the file size configured via the options.

Options:

minimum
The minimum file size to accept in bytes, accepts K / M / G suffixes
maximum
The maximum file size to accept

Internally \TYPO3\CMS\Core\Type\File\FileInfo is used to determine the size.

FloatValidator

Checks if a value is a floating point number.

#[Validate(['validator' => 'Float'])]
protected float $price;
Copied!

ImageDimensionsValidator

The ImageDimensionsValidator validates image dimensions of a given UploadedFile or ObjectStorage with objects of type UploadedFile objects.

Options:

width
The exact width of the image
height
The exact height of the image
minWidth
The minimum width of the image
maxWidth
The maximum width of the image
minHeight
The minimum height of the image
maxHeight
The maximum height of the image

IntegerValidator

The IntegerValidator ensures that a value is an integer.

This validator is useful for validating numeric fields that must contain whole numbers, such as quantities, IDs, or counters.

#[Validate(['validator' => 'Integer'])] protected mixed $quantity;

#[Validate(['validator' => 'Integer'])]
protected mixed $quantity;
Copied!

MimeTypeValidator

The MimeTypeValidator validates MIME types of a given UploadedFile or ObjectStorage with objects of type UploadedFile objects.

Does also validate, if the extension of the validated file matches the allowed file extensions for the detected MIME type.

Options:

allowedMimeTypes
Allowed MIME types (using / IANA media types)
ignoreFileExtensionCheck
If set to true, the file extension check is disabled. Be aware of security implications when setting this to true.

NotEmptyValidator

The NotEmptyValidator ensures that a value is not considered empty.

"Empty" in this context means:

  • An empty string ('')
  • null
  • An empty array ([])
  • An empty ObjectStorage
  • Any empty countable object like \SplObjectStorage

This validator is commonly used to enforce required fields.

#[Validate(['validator' => 'NotEmpty'])]
protected string $title;
Copied!

NumberRangeValidator

The NumberRangeValidator checks that a number falls within a specified numeric range.

This validator supports integers and floats and is useful for validating percentages, prices, limits, or any numeric input with minimum and/or maximum constraints.

Validator options

minimum
Lower boundary of the valid range (inclusive).
maximum
Upper boundary of the valid range (inclusive).
message
Custom error message or translation key for out-of-range values.

If only minimum is set, the validator checks for values greater than or equal to that minimum.

If only maximum is set, it checks for values less than or equal to that maximum.

You may use both together to define an inclusive range.

Example: Validate percentage

use TYPO3\CMS\Extbase\Annotation\Validate;

class SettingsForm
{
    #[Validate([
        'validator' => 'NumberRange',
        'options' => ['minimum' => 1, 'maximum' => 100],
    ])]
    protected int $percentage;
}
Copied!

RegularExpressionValidator

The RegularExpressionValidator checks whether a given value matches a specified regular expression (regex). It is useful for validating custom string formats that are not covered by built-in validators.

For example, it can enforce ID formats, postal codes, or other structured inputs.

Options:

regularExpression
The regular expression to validate against. Must be a valid PCRE pattern, including delimiters (e.g. /^...$/).
message
Custom error message or translation key. If not set, a localized default message will be used. The default message looks cryptic and should not be shown to website visitors as-is.

Validation behavior:

  • If the value does not match, an error is added.
  • If the regex is invalid, an exception is thrown.
  • The validator supports localized error messages via LLL:EXT:... syntax.

Example: username pattern

Validate that a value contains only alphanumeric characters:

use TYPO3\CMS\Extbase\Annotation\Validate;

class UserForm
{
    #[Validate([
        'validator' => 'RegularExpression',
        'options' => [
            'regularExpression' => '/^[a-z0-9]+$/i'
        ]
    ])]
    public string $username = '';
}
Copied!

Example: ZIP code

Validate a 5-digit postal code with a custom error message:

use TYPO3\CMS\Extbase\Annotation\Validate;

class AddressForm
{
    #[Validate([
        'validator' => 'RegularExpression',
        'options' => [
            'regularExpression' => '/^\d{5}$/',
            'message' => 'Bitte eine gültige Postleitzahl eingeben.'
        ]
    ])]
    public string $postalCode = '';
}
Copied!

Use cases

  • Custom identifiers or slugs
  • Postal/ZIP code validation
  • Specific numeric or alphanumeric patterns

Important

Use this validator only for formats that are not supported by dedicated validators. Prefer these built-in validators when applicable:

  • EmailAddressValidator – for email addresses
  • DateTimeValidator – for dates
  • UrlValidator – for URLs

These are easier to configure, localized by default, and more robust.

StringLengthValidator

The StringLengthValidator validates the length of a string.

The check is also multi-byte save. For example "Ö" is counted as ONE charakter.

Options:

minimum
Minimum length for a valid string.
maximum
Maximum length for a valid string.
#[Validate([
    'validator' => 'StringLength',
    'options' => ['minimum' => 5, 'maximum' => 50],
])]
protected string $description;
Copied!

StringValidator

The StringValidator validates that a mixed variable is a string. Fails for array, numbers and bools.

#[Validate(['validator' => 'String'])]
protected mixed $comment;
Copied!

TextValidator

Checks if the given value is a valid text (contains no HTML/XML tags).

#[Validate(['validator' => 'Text'])]
protected string $comment;
Copied!

UrlValidator

The UrlValidator checks whether a given string is a valid web URL.

It uses TYPO3’s internal utility method \TYPO3\CMS\Core\Utility\GeneralUtility::isValidUrl() to determine whether the URL is valid.

Only well-formed URLs with a supported scheme such as http:// or https:// will be accepted.

Validation behavior

  • Only string values are accepted.
  • The URL must include a valid scheme (e.g. https://).
  • Validation will fail for incomplete or malformed URLs.

Example: Validate a web URL

This example ensures that a field contains a valid external website address.

use TYPO3\CMS\Extbase\Annotation\Validate;

class UserProfile
{
    #[Validate(['validator' => 'Url'])]
    protected string $website = '';
}
Copied!

Use cases

  • Website or blog URLs
  • Social media profile links
  • User-submitted external links

Multiple validators example

You can apply multiple validators on a single property.

#[Validate(['validator' => 'NotEmpty'])]
#[Validate([
    'validator' => 'StringLength',
    'options' => ['minimum' => 3, 'maximum' => 20],
])]
protected string $nickname;
Copied!