public class RegexConstraint extends CheckConstraint<String>
CheckConstraint
implementation that checks
whether a string matches the regular expression.Regex
,
ConstraintFactory.regex(String)
,
ConstraintFactory.regex(String, int)
Modifier and Type | Field and Description |
---|---|
protected Pattern |
pattern
Compiled representation of a regular expression.
|
Modifier | Constructor and Description |
---|---|
protected |
RegexConstraint(String regex,
int flags)
Constructs a new
RegexConstraint with the specified regular
expression and flags. |
Modifier and Type | Method and Description |
---|---|
boolean |
appendMessageArguments(ValidationContext<?> context,
Map<String,Object> arguments)
Appends
pattern argument that contains regular expression
pattern. |
protected <T> boolean |
check(String value,
ValidationContext<T> context)
Checks whether the specified string matches the regular expression.
|
Pattern |
getPattern()
Returns compiled representation of a regular expression.
|
Class<?> |
getType()
Returns
java.lang.String type. |
validate
getMessageTemplate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMessageTemplate
protected final Pattern pattern
protected RegexConstraint(String regex, int flags)
RegexConstraint
with the specified regular
expression and flags.regex
- Regular expression pattern.flags
- Match flags.IllegalArgumentException
- if the specified regular expression is
null
or invalid.public final Class<?> getType()
java.lang.String
type.java.lang.String
type.public final Pattern getPattern()
public boolean appendMessageArguments(ValidationContext<?> context, Map<String,Object> arguments)
pattern
argument that contains regular expression
pattern.appendMessageArguments
in interface Constraint<String>
appendMessageArguments
in interface Validation<String>
appendMessageArguments
in class AbstractValidation<String>
context
- Validation context.arguments
- Arguments to be substituted into the error message
template.true
.protected <T> boolean check(String value, ValidationContext<T> context)
check
in class CheckConstraint<String>
T
- The type of validated entity.value
- String to be checked.context
- Validation context.true
if the specified string matches the regular
expression; false
otherwise.Copyright © 2011–2020 FoxLabs. All rights reserved.