Validators

The form framework ships a set of server-side validators, which implement Extbase validators. Be aware that not all of the existing validators are available for each form element, e.g. the "Date range validator" is only available for the "Date" element. Furthermore, some form elements (like "Email") already contain reasonable validators.

With the help of the form element property validationErrorMessages you can define custom validation error messages. The message can also be set within the form editor.

Client-side validation

If a form element is configured accordingly, the form framework adds HTML 5 based frontend validation. Nevertheless, there is no JavaScript validation included by default. We as the TYPO3 core have no plans to opt for a specific solution. This has to be integrated manually. Reliable and maintained projects are Parsley and jQuery Validation.

Localization of client side validations

The displayed validation message is a browser specific text. The output is not generated by TYPO3 and therefore you cannot change it easily. Nevertheless, there is a JavaScript solution for changing the validation message. See Stack Overflow for more information.

Server-side validation

Alphanumeric validator (Alphanumeric)

The "Alphanumeric validator" checks for alphanumeric strings. Alphanumeric is defined as a combination of alphabetic and numeric characters [A-Z + 0-9].

Number of submitted values validator (Count)

The "Number of submitted values validator" checks if the given value contains the specified amount of elements. The validator has 2 options:

  • Minimum [options.minimum]: The minimum count to accept.

  • Maximum [options.maximum]: The maximum count to accept.

Date range validator (DateRange)

The "Date range validator" checks if the given value is a valid DateTime object and in-between a specified date range. The range can be defined by providing a minimum and/or maximum date. The validator has 2 options:

  • Format [options.format]: The format of the minimum and maximum option. Default: [Y-m-d].

  • Minimum date [options.minimum]: The minimum date formatted as Y-m-d.

  • Maximum date [options.maximum]: The maximum date formatted as Y-m-d.

The options minimum and maximum must have the format 'Y-m-d' which represents the RFC 3339 'full-date' format.

The input must be a DateTime object. This input can be tested against a minimum date and a maximum date. The minimum date and the maximum date are strings. The minimum and maximum date can be configured through the validator options.

Date/time validator (DateTime)

The "Date/time validator" checks if the given value is a valid DateTime object. The date string is expected to be formatted according to the W3C standard which is "YYYY-MM-DDT##:##:##+##:##", for example "2005-08-15T15:52:01+00:00".

Email validator (EmailAddress)

The "Email validator" checks if the given value is a valid email address. The format of a valid email address is defined in RFC 3696. The standard allows international characters and the multiple appearance of the @ sign.

File size validator (FileSize)

The "File size validator" validates a file resource regarding its file size. The validator has 2 options:

  • Minimum [options.maximum]: The minimum filesize to accept. Use the format <size>B|K|M|G. For example: 10M means 10 Megabytes.

  • Maximum [options.maximum]: The maximum filesize to accept. Use the format <size>B|K|M|G. For example: 10M means 10 Megabytes.

Use the format <size>B|K|M|G when entering file sizes. For example: 10M means 10 megabytes. Please keep in mind that the maximum file size also depends on the php.ini settings of your environment.

Floating-point number validator (Float)

The "Floating-point number validator" checks if the given value is of type float or a string matching the regular expression [0-9.e+-].

Integer number validator (Integer)

The "Integer number validator" checks if the given value is a valid integer.

Empty validator (NotEmpty)

The "Empty validator" checks if the given value is not empty (NULL, empty string, empty array or empty object).

Number validator (Number)

The "Number validator" checks if the given value is a number.

Number range validator (NumberRange)

The "Number range validator" checks if the given value is a number in the specified range. The validator has 2 options:

  • Minimum [options.minimum]: The minimum value to accept.

  • Maximum [options.minimum]: The maximum value to accept.

Regular expression validator (RegularExpression)

The "Regular expression validator" checks if the given value matches the specified regular expression. Delimiters or modifiers are not supported. The validator has 1 option:

  • Regular expression [options.regularExpression]: The regular expression to use for validation, used as given.

Imagine the following example. You want the user to provide a domain name. The submitted value shall only contain the second and the top level domain, e.g. "typo3.org" instead of "https://typo3.org". The regular expression for this use case would be /^[-a-z0-9]+\.[a-z]{2,6}$/.

String length validator (StringLength)

The "String length validator" checks if the given value is a valid string and its length is in the specified range. The validator has 2 options:

  • Minimum [options.minimum]: The minimum length for a valid string.

  • Maximum [options.minimum]: The maximum length for a valid string.

Non-XML text validator (Text)

The "Non-XML text validator" checks if the given value is a valid text (contains no XML tags). This basically means, that tags are stripped. In this special case quotes are not encoded (see filter_var() for more information.

Be aware that the value of this check entirely depends on the output context. The validated text is not expected to be secure in any circumstance. If you want to be sure of that, use a customized regular expression or filter on output.

Translation of validation messages

To learn more about this topic, please continue here.

Custom validator implementations

Validators belong to a certain prototype and are defined within the validatorsDefinition. The property implementationClassName is used for the validator implementation.

prototypes:
  standard:
    validatorsDefinition:
      Custom:
        implementationClassName: 'VENDOR\MySitePackage\Domain\Validation\CustomValidator'

You can provide options for your validator using the property options. Those will be used as default values which can be overridden within a specific form definition.

Define the default value of the option yourCustomOption:

prototypes:
  standard:
    validatorsDefinition:
      Custom:
        implementationClassName: 'VENDOR\MySitePackage\Domain\Validation\CustomValidator'
        options:
          yourCustomOption: 'Jurian'

Override the default value within your form definition:

identifier: sample-form
label: 'Simple Contact Form'
prototype: standard
type: Form

renderables:
  -
    identifier: subject
    label: 'Name'
    type: Text
    validators:
      -
        identifier: Custom
        options:
          yourCustomOption: 'Mathias'

As mentioned above EXT:form implements Extbase validators. That said, your own validators should extend TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator. Read more about this topic in the Extbase documentation: t3extbasebook:validating-domain-objects.