net.sf.oval.constraint
Annotation Type MatchPattern


@Documented
@Retention(value=RUNTIME)
@Target(value={FIELD,PARAMETER,METHOD})
@Constraint(checkWith=MatchPatternCheck.class)
public @interface MatchPattern

Check if the specified regular expression pattern is matched.

Note: This constraint is also satisfied when the value to validate is null, therefore you might also need to specified @NotNull

Author:
Sebastian Thomschke

Required Element Summary
 String[] pattern
          The regular expression(s) to match against

Examples:
decimal number: "^-{0,1}(\\d*|(\\d{1,3}([,]\\d{3})*))[.]?
 
Optional Element Summary
 ConstraintTarget[] appliesTo
          In case the constraint is declared for an array, collection or map this controls how the constraint is applied to it and it's child objects.
 String errorCode
          error code passed to the ConstraintViolation object
 int[] flags
          Match flags, a bit mask that may include Pattern.CASE_INSENSITIVE, Pattern.MULTILINE, Pattern.DOTALL, Pattern.UNICODE_CASE, Pattern.CANON_EQ
 boolean matchAll
          specifies if all of the declared patterns must match or if one is sufficient
 String message
          message to be used for the ContraintsViolatedException
 String[] profiles
          The associated constraint profiles.
 int severity
          severity passed to the ConstraintViolation object
 String target
          An expression to specify where in the object graph relative from this object the expression should be applied.
 String when
          Formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.
 

Element Detail

pattern

public abstract String[] pattern
The regular expression(s) to match against

Examples:
decimal number: "^-{0,1}(\\d*|(\\d{1,3}([,]\\d{3})*))[.]?\\d*$"
numbers only: "^\\d*$"
e-mail address: "^([a-z0-9]{1,}[\\.\\_\\-]?[a-z0-9]{1,})\\@([a-z0-9]{2,}\\.)([a-z]{2,2}|org|net|com|gov|edu|int|info|biz|museum)$"

See Also:
Pattern

appliesTo

public abstract ConstraintTarget[] appliesTo

In case the constraint is declared for an array, collection or map this controls how the constraint is applied to it and it's child objects.

Default: ConstraintTarget.VALUES

Note: This setting is ignored for object types other than array, map and collection.

Default:
VALUES

errorCode

public abstract String errorCode
error code passed to the ConstraintViolation object

Default:
"net.sf.oval.constraint.MatchPattern"

flags

public abstract int[] flags
Match flags, a bit mask that may include Pattern.CASE_INSENSITIVE, Pattern.MULTILINE, Pattern.DOTALL, Pattern.UNICODE_CASE, Pattern.CANON_EQ

See Also:
Pattern
Default:
0

matchAll

public abstract boolean matchAll
specifies if all of the declared patterns must match or if one is sufficient

Default:
true

message

public abstract String message
message to be used for the ContraintsViolatedException

See Also:
ConstraintViolation
Default:
"net.sf.oval.constraint.MatchPattern.violated"

profiles

public abstract String[] profiles
The associated constraint profiles.

Default:
{}

severity

public abstract int severity
severity passed to the ConstraintViolation object

Default:
0

target

public abstract String target
An expression to specify where in the object graph relative from this object the expression should be applied.

Examples:

  • "owner" would apply this constraint to the current object's property owner
  • "owner.id" would apply this constraint to the current object's owner's property id
  • "jxpath:owner/id" would use the JXPath implementation to traverse the object graph to locate the object where this constraint should be applied.

    Default:
    ""

  • when

    public abstract String when
    Formula returning true if this constraint shall be evaluated and false if it shall be ignored for the current validation.

    Important: The formula must be prefixed with the name of the scripting language that is used. E.g. groovy:_this.amount > 10

    Available context variables are:
    _this -> the validated bean
    _value -> the value to validate (e.g. the field value, parameter value, method return value, or the validated bean for object level constraints)

    Default:
    ""


    Copyright © 2005-2013 The OVal Development Team. All Rights Reserved.