Package io.jmix.ui.component.validation
Class RegexpValidator
java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<String>
io.jmix.ui.component.validation.RegexpValidator
@Scope("prototype")
@Component("ui_RegexpValidator")
public class RegexpValidator
extends AbstractValidator<String>
Regexp validator checks that String value is matched with specified regular expression.
The regular expression follows the Java regular expression conventions.
For error message it uses template string and it is possible to use '${value}' key for formatted output.
In order to provide your own implementation globally, create a subclass and register it in configuration class, for example:
@Bean("ui_RegexpValidator") @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Primary protected RegexpValidator regexpValidator(String regexp) { return new CustomRegexpValidator(regexp); }
- See Also:
-
Field Summary
Fields inherited from class io.jmix.ui.component.validation.AbstractValidator
currentAuthentication, datatypeRegistry, message, messages, substitutor
-
Constructor Summary
ConstructorDescriptionRegexpValidator
(String regexp) RegexpValidator
(String regexp, String message) Constructor for regexp value and custom error message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Checks a value.protected void
setMessages
(Messages messages) void
Sets regexp pattern value.void
setStringSubstitutor
(StringSubstitutor substitutor) Methods inherited from class io.jmix.ui.component.validation.AbstractValidator
formatValue, getMessage, getTemplateErrorMessage, setMessage
-
Field Details
-
pattern
-
-
Constructor Details
-
RegexpValidator
-
RegexpValidator
Constructor for regexp value and custom error message. This message can contain '${value}' key for formatted output. Example: "Invalid value '${value}'".- Parameters:
regexp
- regular expressionmessage
- error message
-
-
Method Details
-
setMessages
-
setStringSubstitutor
-
setRegexp
Sets regexp pattern value.- Parameters:
regexp
- a regexp pattern value
-
getRegexp
- Returns:
- a regexp pattern value
-
accept
Description copied from interface:Validator
Checks a value.- Parameters:
value
- a value- Throws:
ValidationException
-