Regular expressions

There are three elements related to enforcing regular expressions:

  • The regexPattern() element validates the contents of any string property with respect to a regular expression pattern. It is ignored if applied to properties of any other type.

  • The regexPatternFlags() element specifies flags that modify the handling of the pattern. The values are those that would normally be passed to java.util.regex.Pattern#compile(String,int).

  • The regexPatternReplacement() attribute specifies the error message to show if the provided argument does not match the regex pattern.

For example:

import lombok.Getter;
import lombok.Setter;

public class Customer {

    @Property(
        regexPattern = "(\\w+\\.)*\\w+@(\\w+\\.)+[A-Za-z]+",
        regexPatternFlags=Pattern.CASE_INSENSITIVE,
        regexPatternReplacement =
            "Must be valid email address (containing a '@') symbol"   (1)
    )
    @Getter @Setter
    private String email;
}
1 Note that there is currently no i18n support for this phrase.

See also

This attribute can also be specified for parameters.