I want to check the validity of a URL address, so after some research, i find that using apache.commons.validator.UrlValidator class is a good solution to do that, this is an example of code :
import org.apache.commons.validator.UrlValidator; public class ValidateUrlExample{ public static void main(String[] args) { UrlValidator urlValidator = new UrlValidator(); //valid URL if (urlValidator.isValid("http://www.mkyong.com")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } //invalid URL if (urlValidator.isValid("http://invalidURL^$&%$&^")) { System.out.println("url is valid"); } else { System.out.println("url is invalid"); } } } but android doesn't recognize the class "org.apache.commons.validator" Does anyone know what should I do to fix that ?
Thanks in advance
new URL("putyoururlhere")with a invalid url, it throws aMalformedURLException- maybe you can use it. More info at developer.android.com/reference/java/net/…