3.8. Custom data validators configuration

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

Custom data validator, or user-configurable validator is the mechanism allowing users to define their own validation rules. For example, the username must be lowercase, or shorter than 20 characters. In eXo Platform, there are 6 validators that administrators can configure to use and the architecture allows developers to add more validators as they wish.

The validators can be configured via properties in exo.properties file.

A configuration is created by adding an entry with the gatein.validators. prefix in exo.properties file. This prefix is followed by a validator name, a period '.' and a validator aspect. Currently, there are the following validators and validator aspects:

See details about the "username" validator as below. For instructions on how to add a new validator (not in the above list), see Developing your own validator.

Configuration of username validator

By default, the username will be validated as follows:

Note

Some components that leverage GateIn depend on usernames being all lowercase. Therefore, you are strongly recommended to use a lowercase username only.

If you want to validate that username format is email-like, you could use the following configuration:

# validators
gatein.validators.username.regexp=^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$
gatein.validators.username.format.message=Username must be a valid email address

When the username field does not conform to this rule, the account is not created and there will be a warning message:

The field "User Name" must match the format "Username must be a valid email address".

In case you do not define gatein.validators.username.format.message, the value of gatein.validators.username.regexp will be used in the warning message:

The field "User Name" must match the format "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$".
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus