Class RegexpValidator

  • All Implemented Interfaces:
    Validator<java.lang.String>, java.io.Serializable, java.util.function.BiFunction<java.lang.String,​ValueContext,​ValidationResult>
    Direct Known Subclasses:
    EmailValidator

    public class RegexpValidator
    extends AbstractValidator<java.lang.String>
    A string validator comparing the string against a Java regular expression. Both complete matches and substring matches are supported.

    For the Java regular expression syntax, see Pattern.

    Since:
    8.0
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexpValidator​(java.lang.String errorMessage, java.lang.String regexp)
      Creates a validator for checking that the regular expression matches the complete string to validate.
      RegexpValidator​(java.lang.String errorMessage, java.lang.String regexp, boolean complete)
      Creates a validator for checking that the regular expression matches the string to validate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ValidationResult apply​(java.lang.String value, ValueContext context)
      Validates the given value.
      protected boolean isValid​(java.lang.String value)
      Returns whether the given string matches the regular expression.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.function.BiFunction

        andThen
    • Constructor Detail

      • RegexpValidator

        public RegexpValidator​(java.lang.String errorMessage,
                               java.lang.String regexp)
        Creates a validator for checking that the regular expression matches the complete string to validate.
        Parameters:
        errorMessage - the message to display in case the value does not validate.
        regexp - a Java regular expression
      • RegexpValidator

        public RegexpValidator​(java.lang.String errorMessage,
                               java.lang.String regexp,
                               boolean complete)
        Creates a validator for checking that the regular expression matches the string to validate.
        Parameters:
        errorMessage - the message to display in case the value does not validate.
        regexp - a Java regular expression
        complete - true to use check for a complete match, false to look for a matching substring
    • Method Detail

      • apply

        public ValidationResult apply​(java.lang.String value,
                                      ValueContext context)
        Description copied from interface: Validator
        Validates the given value. Returns a ValidationResult instance representing the outcome of the validation.
        Parameters:
        value - the input value to validate
        context - the value context for validation
        Returns:
        the validation result
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isValid

        protected boolean isValid​(java.lang.String value)
        Returns whether the given string matches the regular expression.
        Parameters:
        value - the string to match
        Returns:
        true if the string matched, false otherwise