Page History
Status | ||||
---|---|---|---|---|
|
Note |
---|
This field validator definition has been deprecated since Magnolia 6.0. It is part of the Magnolia 5 UI framework. For the updated implementation, see Field validators for Magnolia 6 UI instead. |
Validators ensure that field input is entered in 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 like a chain, one after the other.
Table of Contents |
---|
Common validator properties
Simple validator definition:
Localtab Group | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Properties:
<field name> | Name of field. | ||||||
| required Contains the validator definition. | ||||||
| required Arbitrary node name. Use a name that describes the validator type. | ||||||
| required Validator definition class. Use the fully-qualified class name. | ||||||
| optional Fully qualified name of the Java class that creates the validator. The class must implement
| ||||||
| optional Text displayed to the user on invalid input. Text string or message bundle key. | ||||||
| optional Message bundle for localized messages. This property can be set at dialog, form, tab or field level. | ||||||
| required for regex validation Regular expression pattern when using the |
List of validator definition classes
info.magnolia.ui.form.validator.definition.RegexpValidatorDefinition | Validates a regular expression given in the |
info.magnolia.ui.form.validator.definition.EmailValidatorDefinition | Validates an email address. Delegates to a Vaadin |
Custom regular expressions
The easiest custom validator is a regular expression. Use the
Javadoc resource link | ||||
---|---|---|---|---|
|
pattern
property.Here is an example of validating a ZIP code (U.S. postal code).
Localtab Group | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Custom validators
To write your own validator class:
- Create a validator class that performs the actual validation.
- Create a validator factory class that extends
. Implement theJavadoc resource link className info.magnolia.ui.form.validator.factory.AbstractFieldValidatorFactory renderType asynchronous createValidator
method. - Create a validator definition class that extends
. In the definition class, set the factory class.Javadoc resource link className info.magnolia.ui.form.validator.definition.ConfiguredFieldValidatorDefinition renderType asynchronous
Example: Checking that a username is unique.
Javadoc resource link className info.magnolia.security.app.dialog.field.validator.UniqueUserNameValidator renderType asynchronous Javadoc resource link className info.magnolia.security.app.dialog.field.validator.UniqueUserNameValidatorFactory renderType asynchronous Javadoc resource link className info.magnolia.security.app.dialog.field.validator.UniqueUserNameValidatorDefinition renderType asynchronous
Checking for null values
Info | |||||||
---|---|---|---|---|---|---|---|
| |||||||
|