Field validators
Validators ensure that field input is entered in the correct format and
length. For example, you can validate that an email address adheres to a
syntax such as first.last@company.com
. You can add multiple validators
to a field. The validators are executed in a chain, one after the other.
This field validator definition is part of the Magnolia 6 UI
framework. The fully qualified class name is
If you work with the Magnolia 5 UI framework, see Field validators for Magnolia 5 UI instead. |
Example definition
email:
label: Email
$type: textField
required: true
validators:
email:
$type: emailValidator
errorMessage: Enter a valid email address
Validator properties
Property | Description | ||
---|---|---|---|
|
required List of field validator definition items. Any value must be a subtype of
|
||
|
required Arbitrary validator name. Use a name that describes the validator type. |
||
|
required (unless Validator definition class. Use the fully qualified class name. See Validator types for possible values. You can also create your own validator definition class. |
||
|
You can use this as a shortcut for Example class annotation
To use the |
||
|
required (used only in node name validation), default is Validation mode when using
|
||
|
required (used only in node name and regex validation), default is Regular expression pattern to validate against when using
|
||
|
optional Fully qualified name of the Java class that creates the validator. The
class must implement |
||
|
optional Error message displayed on invalid input. The value can be literal or retrieved from the message bundle with a key. Use alphanumeric characters in literal values. |
Custom validators
To write your own validator definition class:
-
Create a validator class that performs the actual validation.
-
Create a validator factory class that extends
info.magnolia.ui.field.AbstractFieldValidatorFactory
. Implement thecreateValidator
method. -
Create a validator definition class that extends
info.magnolia.ui.field.ConfiguredFieldValidatorDefinition
. In the definition class, set the factory class.
Validator types
$type | class/description |
---|---|
|
Validates an email address. Delegates to Vaadin
|
|
Validates JCR node names as defined in the |
|
Validates text input as defined in the |