In this example, let’s us see how to validate URL in Java.
Source Code
package com.beginner.examples;
import org.apache.commons.validator.UrlValidator;
public class ValidateURL {
public static void main(String[] args) {
UrlValidator urlValidator = new UrlValidator();
String validURL = "http://www.google.com";
String invalidURL = "http://www.aasdf@$#.com";
System.out.println(urlValidator.isValid(validURL));
System.out.println(urlValidator.isValid(invalidURL));
}
}
Output:
true
false