<validators> <!-- Plain Validator Syntax --> <validator type="url"> <param name="fieldName">myHomePage</param> <message>Invalid homepage url</message> </validator> <!-- Field Validator Syntax --> <field name="myHomepage"> <field-validator type="url"> <message>Invalid homepage url</message> </field-validator> </field> </validators>@author $Author$ @version $Date$ $Revision$
UrlValidator
validates the string argument values are URLs. If the value is a URL, the string value in the {@link java.util.List} of values is replaced with the{@link java.net.URL} instance.URLs can also be validated based on their scheme by using the {@link #setProtocol setProtocol} method, or by using the specified{@link #UrlValidator(java.lang.String) constructor}. The following example shows how to limit the valid values for the site argument to 'https' URLs. ... ArgumentBuilder builder = new ArgumentBuilder(); Argument site = builder.withName("site"); .withValidator(new URLValidator("https"));@author Rob Oxspring @author John Keyes
Example of usage: Construct a UrlValidator with valid schemes of "http", and "https". String[] schemes = {"http","https"}. UrlValidator urlValidator = new UrlValidator(schemes); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints "url is invalid" If instead the default constructor is used. UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints out "url is valid"@see Uniform Resource Identifiers (URI): Generic Syntax @version $Revision: 478334 $ $Date: 2006-11-22 21:31:54 +0000 (Wed, 22 Nov 2006) $ @since Validator 1.1
Example of usage: Construct a UrlValidator with valid schemes of "http", and "https". String[] schemes = {"http","https"}. UrlValidator urlValidator = new UrlValidator(schemes); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints "url is invalid" If instead the default constructor is used. UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints out "url is valid"@see Uniform Resource Identifiers (URI): Generic Syntax @version $Revision: 1227719 $ $Date: 2012-01-05 17:45:51 +0000 (Thu, 05 Jan 2012) $ @since Validator 1.4
Example of usage: UrlValidator urlValidator = UrlValidator.get(); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints out "url is valid"
Based on UrlValidator code from Apache commons-validator.
@see Uniform Resource Identifiers (URI): Generic Syntaxhttps://
, and ftp://
. The behavior of validation is modified by passing in one of these options:
ALLOW_2_SLASHES - [FALSE]
: Allows double '/' characters in the path component.NO_FRAGMENT- [FALSE]
: By default fragments are allowed. If this option is included then fragments are flagged as illegal.ALLOW_ALL_SCHEMES - [FALSE]
: By default only http, https, and ftp are considered valid schemes. Enabling this option will let any scheme pass validation. This was originally based org.apache.commons.validator.UrlValidator
, but the dependency on Jakarta-ORO was removed and it now uses java.util.regexp instead. Usage example:
<code> Component.add(new UrlValidator({"http", "https"})); </code>@author Vincent Demay @since 1.2.6 @see "http://www.ietf.org/rfc/rfc2396.txt"
Example of usage: Construct a UrlValidator with valid schemes of "http", and "https". String[] schemes = {"http","https"}. UrlValidator urlValidator = new UrlValidator(schemes); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints "url is invalid" If instead the default constructor is used. UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid("ftp://foo.bar.com/")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } prints out "url is valid"@see Uniform Resource Identifiers (URI): Generic Syntax @since Validator 1.4
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|