Class Validator

    • Constructor Detail

      • Validator

        public Validator()
    • Method Detail

      • hasError

        public boolean hasError​(String name)
        Checks if a give field has a validation error
        Parameters:
        name - The field to check
        Returns:
        True if the field has a validation error, false otherwise
      • getError

        public String getError​(String name)
        Retrieves the error message for a given field
        Parameters:
        name - The field to check
        Returns:
        The error message for the field, or an empty string if no error is found
      • expectValue

        public void expectValue​(String name)
        Validates a given field to be present with a value
        Parameters:
        name - The field to check
      • expectValue

        public void expectValue​(String name,
                                String message)
        Validates a given field to be present with a value
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectMin

        public void expectMin​(String name,
                              double minLength)
        Validates a given field to have a minimum length
        Parameters:
        name - The field to check
        minLength - The minimum length
      • expectMin

        public void expectMin​(String name,
                              double minLength,
                              String message)
        Validates a given field to have a minimum length
        Parameters:
        name - The field to check
        minLength - The minimum length
        message - A custom error message instead of the default one
      • expectMax

        public void expectMax​(String name,
                              double maxLength)
        Validates a given field to have a maximum length
        Parameters:
        maxLength - The maximum length
        name - The field to check
      • expectNumeric

        public void expectNumeric​(String name)
        Validates that a given field has a numeric value
        Parameters:
        name - The field to check
      • expectNumeric

        public void expectNumeric​(String name,
                                  String message)
        Validates that a given field has a numeric value
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectMax

        public void expectMax​(String name,
                              double maxLength,
                              String message)
        Validates a given field to have a maximum length
        Parameters:
        name - The field to check
        maxLength - The maximum length
        message - A custom error message instead of the default one
      • expectExactMatch

        public void expectExactMatch​(String name,
                                     String anotherName)
        Validates to fields to exactly (case-sensitive) match
        Parameters:
        name - The field to check
        anotherName - The other field to check against
      • expectExactMatch

        public void expectExactMatch​(String name,
                                     String anotherName,
                                     String message)
        Validates to fields to exactly (case-sensitive) match
        Parameters:
        name - The field to check
        anotherName - The other field to check against
        message - A custom error message instead of the default one
      • expectMatch

        public void expectMatch​(String name,
                                String anotherName)
        Validates to fields to (case-insensitive) match
        Parameters:
        name - The field to check
        anotherName - The field to check against
      • expectMatch

        public void expectMatch​(String name,
                                String anotherName,
                                String message)
        Validates to fields to (case-insensitive) match
        Parameters:
        name - The field to check
        anotherName - The field to check against
        message - A custom error message instead of the default one
      • expectMatch

        public void expectMatch​(String name,
                                List<String> values)
        Validates to list of given values to (case-sensitive) match
        Parameters:
        name - The field to check
        values - A list of given values to check against
      • expectMatch

        public void expectMatch​(String name,
                                String message,
                                List<String> values)
        Validates to fields to (case-sensitive) match
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
        values - A list of given values to check against
      • expectEmail

        public void expectEmail​(String name)
        Validates a field to be a valid email address
        Parameters:
        name - The field to check
      • expectEmail

        public void expectEmail​(String name,
                                String message)
        Validates a field to be a valid email address
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectIpv4

        public void expectIpv4​(String name)
        Validates a field to be a valid IPv4 address
        Parameters:
        name - The field to check
      • expectIpv4

        public void expectIpv4​(String name,
                               String message)
        Validates a field to be a valid IPv4 address
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectDomainName

        public void expectDomainName​(String name)
        Validates a field to be a valid IPv4 address
        Parameters:
        name - The field to check
      • expectDomainName

        public void expectDomainName​(String name,
                                     String message)
        Validates a field to be a valid IPv4 address
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectIpv6

        public void expectIpv6​(String name)
        Validates a field to be a valid IPv6 address
        Parameters:
        name - The field to check
      • expectIpv6

        public void expectIpv6​(String name,
                               String message)
        Validates a field to be a valid IPv6 address
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • expectRange

        public void expectRange​(String name,
                                int minLength,
                                int maxLength)
        Validates a field to be in a certain range
        Parameters:
        name - The field to check
        minLength - The minimum length
        maxLength - The maximum length
      • expectRange

        public void expectRange​(String name,
                                int minLength,
                                int maxLength,
                                String message)
        Validates a field to be in a certain range
        Parameters:
        name - The field to check
        minLength - The minimum length
        maxLength - The maximum length
        message - A custom error message instead of the default one
      • expectRegex

        public void expectRegex​(String name,
                                com.google.re2j.Pattern pattern)
        Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g. Pattern pattern = Pattern.compile("[a-Z,0-9]")
        Parameters:
        name - The field to check
        pattern - The pre-compiled pattern
      • expectRegex

        public void expectRegex​(String name,
                                com.google.re2j.Pattern pattern,
                                String message)
        Validates a field by a given regular expression pattern It is required to pass a pre-compiled pattern, e.g. Pattern pattern = Pattern.compile("[a-Z,0-9]")
        Parameters:
        pattern - The pre-compiled pattern
        name - The field to check
        message - A custom error message instead of the default one
      • expectUrl

        public void expectUrl​(String name)
        Validates field to be a valid URL
        Parameters:
        name - The field to check
      • expectUrl

        public void expectUrl​(String name,
                              String message)
        Validates field to be a valid URL
        Parameters:
        name - The field to check
        message - A custom error message instead of the default one
      • validateTrue

        public void validateTrue​(boolean value,
                                 String name,
                                 String message)
        Validates a given value to be true
        Parameters:
        value - The value to check
        name - The name of the field to display the error message
        message - A custom error message instead of the default one
      • validateTrue

        public void validateTrue​(boolean value,
                                 String name)
        Validates a given value to be true
        Parameters:
        value - The value to check
        name - The name of the field to display the error message
      • validateFalse

        public void validateFalse​(boolean value,
                                  String name,
                                  String message)
        Validates a given value to be false
        Parameters:
        value - The value to check
        name - The name of the field to display the error message
        message - A custom error message instead of the default one
      • validateFalse

        public void validateFalse​(boolean value,
                                  String name)
        Validates a given value to be false
        Parameters:
        value - The value to check
        name - The name of the field to display the error message
      • validateNotNull

        public void validateNotNull​(Object object,
                                    String name,
                                    String message)
        Validates a given object to be not null
        Parameters:
        object - The object to check
        name - The name of the field to display the error message
        message - A custom error message instead of the default one
      • validateNotNull

        public void validateNotNull​(Object object,
                                    String name)
        Validates a given object to be not null
        Parameters:
        object - The object to check
        name - The name of the field to display the error message
      • validateNull

        public void validateNull​(Object object,
                                 String name,
                                 String message)
        Validates a given object to be null
        Parameters:
        object - The object to check
        name - The name of the field to display the error message
        message - A custom error message instead of the default one
      • validateNull

        public void validateNull​(Object object,
                                 String name)
        Validates a given object to be null
        Parameters:
        object - The object to check
        name - The name of the field to display the error message
      • hasErrors

        public boolean hasErrors()
        Checks if any field in the validation has an error
        Returns:
        True if at least one field has an error, false otherwise
      • get

        public String get​(String key)
        Retrieves a form value corresponding to the name of the form element
        Parameters:
        key - The name of the form element
        Returns:
        The value of the form or null if not present
      • addValue

        public void addValue​(String key,
                             String value)
      • isValid

        public boolean isValid()
      • invalidate

        public void invalidate()