Class RegexpValidator

java.lang.Object
io.jmix.ui.component.validation.AbstractValidator<String>
io.jmix.ui.component.validation.RegexpValidator
All Implemented Interfaces:
Validator<String>, Consumer<String>

@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 Details

    • pattern

      protected Pattern pattern
  • Constructor Details

    • RegexpValidator

      public RegexpValidator(String regexp)
    • RegexpValidator

      public RegexpValidator(String regexp, String message)
      Constructor for regexp value and custom error message. This message can contain '${value}' key for formatted output. Example: "Invalid value '${value}'".
      Parameters:
      regexp - regular expression
      message - error message
  • Method Details

    • setMessages

      @Autowired protected void setMessages(Messages messages)
    • setStringSubstitutor

      @Autowired public void setStringSubstitutor(StringSubstitutor substitutor)
    • setRegexp

      @StudioProperty(required=true) public void setRegexp(String regexp)
      Sets regexp pattern value.
      Parameters:
      regexp - a regexp pattern value
    • getRegexp

      public String getRegexp()
      Returns:
      a regexp pattern value
    • accept

      public void accept(String value) throws ValidationException
      Description copied from interface: Validator
      Checks a value.
      Parameters:
      value - a value
      Throws:
      ValidationException