Class RegexpURLValidator

java.lang.Object
org.hibernate.validator.constraintvalidators.RegexpURLValidator
All Implemented Interfaces:
ConstraintValidator<URL,CharSequence>

public class RegexpURLValidator extends Object implements ConstraintValidator<URL,CharSequence>
Validate that the character sequence (e.g. string) is a valid URL using a regular expression.
Since:
5.2
Author:
Hardy Ferentschik
  • Constructor Details

    • RegexpURLValidator

      public RegexpURLValidator()
  • Method Details

    • initialize

      public void initialize(URL url)
      Description copied from interface: ConstraintValidator
      Initializes the validator in preparation for ConstraintValidator.isValid(Object, ConstraintValidatorContext) calls. The constraint annotation for a given constraint declaration is passed.

      This method is guaranteed to be called before any use of this instance for validation.

      The default implementation is a no-op.

      Specified by:
      initialize in interface ConstraintValidator<URL,CharSequence>
      Parameters:
      url - annotation instance for a given constraint declaration
    • isValid

      public boolean isValid(CharSequence value, ConstraintValidatorContext constraintValidatorContext)
      Description copied from interface: ConstraintValidator
      Implements the validation logic. The state of value must not be altered.

      This method can be accessed concurrently, thread-safety must be ensured by the implementation.

      Specified by:
      isValid in interface ConstraintValidator<URL,CharSequence>
      Parameters:
      value - object to validate
      constraintValidatorContext - context in which the constraint is evaluated
      Returns:
      false if value does not pass the constraint