Built-in validators provided by Extbase
This document lists all built-in Extbase validators, along with example usage for each using PHP attributes.
See also
Note
All validators except the NotEmptyValidator
accept empty values as valid. If empty values should not be possible,
combine these validators with the Not
.
Validators in Extbase
AlphanumericValidator
The
Alphanumeric
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;
BooleanValidator
The
Boolean
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
orfalse
, such as for checkboxes in forms.Interprets strings
'true'
,'1'
,'false'
,'0'
. Values of other types are converted to boolean directly.
Note
Empty strings ''
and null
are always validated, regardless of the is
option.
If you want to deny empty strings a null
, combine this validator with
the NotEmptyValidator.
Ensure that a value is a boolean (no strict check, default behavior):
#[Validate(['validator' => 'Boolean'])]
protected $isActive;
Require that a value must be true
(e.g. checkbox must be checked):
#[Validate(['validator' => 'Boolean', 'options' => ['is' => true]])]
protected bool $termsAccepted;
Require that a value must be false
:
#[Validate(['validator' => 'Boolean', 'options' => ['is' => false]])]
protected bool $isBlocked;
CollectionValidator
The
Collection
is a built-in Extbase validator for validating arrays
or collections, such as arrays of DTOs or Object
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.
element
Validator - The name or class of a validator that should be applied
to each item in the collection (e.g.
'Not
,Empty' 'Email
).Address' element
Type - 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 element
or element
.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
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
Object
propertyStorage
Note
Validation will be skipped if neither element
nor
element
is set.
ConjunctionValidator
The
Conjunction
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
#
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.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
Note
If you use multiple #
attributes on a single
property, Extbase automatically applies them using a Conjunction
.
You do not need to instantiate it manually in most use cases.
DateTimeValidator
The
Date
ensures a value is a valid
\Date
.
#[Validate(['validator' => 'DateTime'])]
protected mixed $startDate;
DisjunctionValidator
The
Disjunction
is a composite Extbase validator that allows you to
combine multiple validators using a logical OR.
It is the inverse of the Conjunction
: 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.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
Note
Extbase does not automatically construct disjunctions for you.
You must manually create and configure a Disjunction
when needed.
It is not currently possible to use this validator directly via
#
annotations.
EmailAddressValidator
The
Email
an email address using method
\TYPO3\
,
which uses the validators defined in
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['validators'].
It respects
#[Validate(['validator' => 'EmailAddress'])]
protected string $email;
FileNameValidator
The
File
validates, that the given
Uploaded
or
Object
with objects of type Uploaded
objects does not contain a PHP executable file by checking the given file
extension.
Internally the
\TYPO3\
is
used to validate the file name.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
FileSizeValidator
The
File
validates, that the given
Uploaded
Object
with objects of type Uploaded
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\
is used to determine the
size.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
FloatValidator
Checks if a value is a floating point number.
#[Validate(['validator' => 'Float'])]
protected float $price;
ImageDimensionsValidator
The
Image
validates image dimensions of a given
Uploaded
or
Object
with objects of type Uploaded
objects.
Options:
width
- The exact width of the image
height
- The exact height of the image
min
Width - The minimum width of the image
max
Width - The maximum width of the image
min
Height - The minimum height of the image
max
Height - The maximum height of the image
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
IntegerValidator
The
Integer
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;
MimeTypeValidator
The
Mime
validates MIME types of a given
Uploaded
or
Object
with objects of type Uploaded
objects.
Does also validate, if the extension of the validated file matches the allowed file extensions for the detected MIME type.
Options:
allowed
Mime Types - Allowed MIME types (using / IANA media types)
ignore
File Extension Check - If set to
true
, the file extension check is disabled. Be aware of security implications when setting this totrue
.
Note
We are still missing working examples for this validator. Click the "Report Issue" button on the top of this page and send us your examples.
NotEmptyValidator
The
Not
ensures that a value is not considered empty.
"Empty" in this context means:
- An empty string (
''
) null
- An empty array (
[]
) - An empty
Object
Storage - Any empty countable object like
\Spl
Object Storage
This validator is commonly used to enforce required fields.
#[Validate(['validator' => 'NotEmpty'])]
protected string $title;
NumberRangeValidator
The
Number
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;
}
RegularExpressionValidator
The
Regular
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.
Note
The default error message of the RegularExpressionValidator looks very cryptic for end users as it repeats the regular expression. Provide an individualized error message.
Options:
regular
Expression - 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:
syntax.EXT:...
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 = '';
}
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 = '';
}
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:
Email
– for email addressesAddress Validator Date
– for datesTime Validator Url
– for URLsValidator
These are easier to configure, localized by default, and more robust.
StringLengthValidator
The
String
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;
Note
Even if the minimum
option is set, empty strings are accepted as valid.
Combine this validator with the NotEmptyValidator
to disallow empty strings.
StringValidator
The
String
validates that a mixed variable is a string. Fails for array, numbers and bools.
#[Validate(['validator' => 'String'])]
protected mixed $comment;
TextValidator
Checks if the given value is a valid text (contains no HTML/XML tags).
Note
Be aware that the value of this check entirely depends on the output context. The validated text is not expected to be secure in every circumstance, if you want to be sure of that, use a customized regular expression or filter on output.
#[Validate(['validator' => 'Text'])]
protected string $comment;
UrlValidator
The
Url
checks
whether a given string is a valid web URL.
It uses TYPO3’s internal utility method
\TYPO3\
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 = '';
}
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;