[#javax-validation-constraints-Pattern]
= @Pattern (javax.validation)

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



The `@javax.validation.constraints.Pattern` annotation is recognized by Apache Causeway 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:

[source,java]
----
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:

[source,java]
----
@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:

[source,java]
----
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;
----

