This validator checks that a field is a valid URL.
Usage
The annotation must be applied at method level.
Parameters
Parameter | Required | Default | Notes |
---|
message | yes | |
...
Wiki Markup |
---|
{snippet:id=description|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.UrlValidator} |
Usage
Wiki Markup |
---|
{snippet:id=usage|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.UrlValidator} |
Parameters
Wiki Markup |
---|
{snippet:id=parameters|javadoc=true|url=com.opensymphony.xwork2.validator.annotations.UrlValidator} |
Examples
| field error message |
key | no | | i18n key from language specific properties file |
messageParams | no | | additional params to be used to customize message - will be evaluated against the Value Stack |
fieldName | no | | field name under validation |
shortCircuit | no | false | if this validator should be used as shortCircuit |
urlRegex | no | | defines regex to use to validate url |
urlRegexExpression | no | | defines regex as expression to validate url, expression will be evaluated against current stack to get proper regex |
type | yes | ValidatorType.FIELD | Enum value from ValidatorType. Either FIELD or SIMPLE can be used here |
Examples
Code Block |
---|
language | java |
---|
title | UrlValidator usage example |
---|
|
@UrlValidator(message = "Default message", key = "i18n.key", shortCircuit = true) |
Code Block |
---|
language | java |
---|
title | UrlValidator usage example |
---|
|
@UrlValidator(message = "Default message", key = "i18n.key", urlRegexExpression = "${urlRegex}") |
Note |
---|
urlRegex neither urlRegexExpression are only used on client side to validate URLs - this will be changed with next major release!
|
Note |
---|
If no urlRegex neither urlRegexExpression is defined, default regex will be used instead, based on StackOverflow answer |
Code Block |
---|
language | java |
---|
title | Default URL regex |
---|
|
return "^(https?|ftp):\/\/" +
"(([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+" +
"(:([a-z0-9$_\\.\\+!\\*\\'\\(\\),;\\?&=-]|%[0-9a-f]{2})+)?" +
"@)?(#?" +
")((([a-z0-9]\\.|[a-z0-9][a-z0-9-]*[a-z0-9]\\.)*" +
"[a-z][a-z0-9-]*[a-z0-9]" +
"|((\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])\\.){3}" +
"(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])" +
")(:\\d+)?" +
")(((\\/+([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)*" +
"(\\?([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)" +
"?)?)?" +
"(#([a-z0-9$_\\.\\+!\\*\\'\\(\\),;:@&=-]|%[0-9a-f]{2})*)?" +
"$"; |
Wiki Markup |
---|
{snippet:id=example|javadoc=true|lang=java|url=com.opensymphony.xwork2.validator.annotations.UrlValidator} |