Regular Expressions
String parameters can be checked to ensure that they match a regular expression. There are three elements involved in this:
-
The regexPattern() element validates the contents of any string parameter with respect to a regular expression pattern. It is ignored if applied to parameters 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() element specifies the error message to show if the provided argument does not match the regex pattern.
For example:
public class Customer {
public void updateEmail(
@Parameter(
regexPattern = "(\\w+\\.)*\\w+@(\\w+\\.)+[A-Za-z]+",
regexPatternFlags = Pattern.CASE_INSENSITIVE,
regexPatternReplacement =
"Must be valid email address " +
"(containing a '@') symbol" (1)
)
@ParameterLayout(named = "Email")
final String email) {
...
}
)
| 1 | Note that there is currently no i18n support for this phrase. |