How to verify if a String is valid URL (including deeplink) in Java. The method should return true for the following test cases
http://www.example.com/gizmos
https://www.example.com/gizmos
example://gizmos
How to verify if a String is valid URL (including deeplink) in Java. The method should return true for the following test cases
http://www.example.com/gizmos
https://www.example.com/gizmos
example://gizmos
Try using UrlValidator class from the Apache Commons Validator project.
String[] URLPrefixes = {"http","https", "example"};
UrlValidator urlValidator = new UrlValidator(URLPrefixes);
if (urlValidator.isValid("http://www.example.com/gizmos")) {
System.out.println("URL is valid");
} else {
System.out.println("URL is invalid");
}