Java源码示例:org.apache.commons.validator.UrlValidator
示例1
private static boolean isValidRelativeURL(String url) {
String absoluteUrl = "http://mynonexistingserver.something.smt:99999" + url;
UrlValidator urlValidator = new UrlValidator();
if (urlValidator.isValid(absoluteUrl)) {
return true;
} else {
return false;
}
}
示例2
/**
* Method to verify url is valid or not.
*
* @param url String
* @return boolean
*/
public static boolean isUrlvalid(String url) {
String[] schemes = {"http", "https"};
UrlValidator urlValidator = new UrlValidator(schemes);
return urlValidator.isValid(url);
}
示例3
/**
* Validates if an url is a valid url address
*
* @param url url address to validate
* @return
*/
public static boolean validateUrl(String url) {
String[] schemes = {"https"};
UrlValidator urlValidator = new UrlValidator(schemes);
return urlValidator.isValid(url);
}