Class UrlValidator
java.lang.Object
ca.corbett.forms.validators.UrlValidator
- All Implemented Interfaces:
FieldValidator<ShortTextField>
A simple FieldValidator that can be attached to any ShortTextField to ensure that the
field's value is either blank or a valid URL. If blank values are not permitted,
you can use the overloaded constructor to disallow them. Blank values are
considered valid by default.
- Since:
- swing-extras 3.0
- Author:
- scorbo2
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisValidUrl(String url) A public convenience method for validating URLs.validate(ShortTextField fieldToValidate) Performs validation on the field in question, and returns a ValidationResult as appropriate.
-
Field Details
-
MESSAGE
- See Also:
-
-
Constructor Details
-
UrlValidator
public UrlValidator() -
UrlValidator
public UrlValidator(boolean allowBlank)
-
-
Method Details
-
validate
Description copied from interface:FieldValidatorPerforms validation on the field in question, and returns a ValidationResult as appropriate. Here you can do whatever checks you need to do, either on the FormField in question, or on other FormFields on the same FormPanel if you have references to them, or to whatever other state your application maintains. If you wish to signal a validation error, it's highly recommended to make sure you give some clue as to what the user can do to fix the problem.An example of bad validation:
return new ValidationResult(false, "Something bad happened.");
An example of good validation:
return new ValidationResult(false, "Value must be less than 10.");
- Specified by:
validatein interfaceFieldValidator<ShortTextField>- Parameters:
fieldToValidate- The FormField to be validated.- Returns:
- A ValidationResult which describes whether the current value in our field is valid.
Returning
nullis discouraged but treated the same asValidationResult.valid().
-
isValidUrl
A public convenience method for validating URLs. We defer this validation to thejava.net.URLandjava.net.URIclasses.- Parameters:
url- A URL in string form.- Returns:
- true if the URL is well-formed.
-