@Pattern (javax)

The @javax.validation.constraints.Pattern annotation is recognized by Apache Isis as a means to specify a regular expression constraint for properties and action parameters of type java.lang.String.

For example, here’s the annotation being used on an action parameter:

public Customer updateName(
                    @javax.validation.constraints.Pattern(
                        regexp="[A-Z].+"
                        message="Must begin with a capital."
                    )
                    final String name) {
    setName(name);
    return this
}
...

and here’s an example of its use on a property:

@javax.validation.constraints.Pattern(
    regexp="[A-Z].+"
    message="Must begin with a capital."
)
public String getName() {
    return name;
}
...

For properties, it is also possible to specify against a field if Lombok is being used:

import javax.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

@Pattern(
    regexp="[A-Z].+"
    message="Must begin with a capital."
)
@Getter @Setter
private String name;