Annotation Interface ValidURL
CharSequence represents a valid URL.
This annotation can be used to validate that a string field, parameter, etc. contains a valid URL.
By default, only HTTP and HTTPS schemes are allowed, but this can be configured using the
allowAllSchemes() and allowSchemes() properties.
- Implementation Note:
- This annotation requires the commons-validator dependency
when using it, since the
ValidURLValidatoruses Apache Commons Validator'sUrlValidatorinternally.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether to allow all URL schemes.booleanWhether to allow URLs with fragments.booleanWhether to allow local URLs (e.g.,localhost,localdomain).booleanWhether to allow null values.String[]The allowed URL schemes.booleanWhether to allow URLs with two consecutive slashes.Class<?>[]The validation groups to which this constraint belongs.The error message to use when validation fails.Class<? extends jakarta.validation.Payload>[]The payload associated with the constraint.
-
Element Details
-
message
String messageThe error message to use when validation fails.- Returns:
- the error message
- Default:
- "{org.kiwiproject.validation.ValidURL.message}"
-
groups
Class<?>[] groupsThe validation groups to which this constraint belongs.This is a standard property from the Bean Validation API.
- Returns:
- the validation groups
- Default:
- {}
-
payload
Class<? extends jakarta.validation.Payload>[] payloadThe payload associated with the constraint.This is a standard property from the Bean Validation API.
- Returns:
- the payload
- Default:
- {}
-
allowNull
boolean allowNullWhether to allow null values.If set to true, null values will be considered valid. If set to false (the default), null values will be considered invalid.
- Returns:
- true if null values are allowed, false otherwise
- Default:
- false
-
allowAllSchemes
boolean allowAllSchemesWhether to allow all URL schemes.If set to true, all URL schemes will be allowed. If set to false (the default), only the schemes specified in
allowSchemes()will be allowed.- Returns:
- true if all schemes are allowed, false otherwise
- Default:
- false
-
allowSchemes
String[] allowSchemesThe allowed URL schemes.This property is only used if
allowAllSchemes()is set to false. By default, only "http" and "https" schemes are allowed.- Returns:
- the allowed URL schemes
- Default:
- {"http", "https"}
-
allowLocalUrls
boolean allowLocalUrlsWhether to allow local URLs (e.g.,localhost,localdomain).If set to true (the default), local URLs like
http://localhostwill be considered valid. If set to false, local URLs will be considered invalid.- Returns:
- true if local URLs are allowed, false otherwise
- Default:
- true
-
allowTwoSlashes
boolean allowTwoSlashesWhether to allow URLs with two consecutive slashes.If set to true, URLs with two consecutive slashes (other than after the scheme) will be considered valid. If set to false (the default), such URLs will be considered invalid.
- Returns:
- true if URLs with two consecutive slashes are allowed, false otherwise
- Default:
- false
-
allowFragments
boolean allowFragmentsWhether to allow URLs with fragments.If set to true (the default), URLs with fragments (the part after #) will be considered valid. If set to false, URLs with fragments will be considered invalid.
- Returns:
- true if URLs with fragments are allowed, false otherwise
- Default:
- true
-