Java URL Value Check isValidURL(String urlStr)

Here you can find the source of isValidURL(String urlStr)

Description

Checks whether the given string is a valid URL.

License

Open Source License

Parameter

Parameter Description
urlStr URL string to check

Return

true if valid URL, else false

Declaration

public static boolean isValidURL(String urlStr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**//from  w ww.j a v a2  s.  c  o m
     * Checks whether the given string is a valid URL.
     * 
     * @param urlStr  URL string to check
     * @return true if valid URL, else false
     */
    public static boolean isValidURL(String urlStr) {

        if (urlStr == null) {
            return false;
        }

        try {
            URI uri = new URI(urlStr);
            if (uri.getScheme() == null) {
                return false;
            }

            return uri.getScheme().equals("http") || uri.getScheme().equals("https");
        } catch (URISyntaxException e) {
            return false;
        }
    }
}

Related

  1. isValidURL(String url)
  2. isValidUrl(String url)
  3. isValidURL(String url)
  4. isValidURL(String url)
  5. isValidURL(String URL_String)
  6. isValidURL(String urlStr)
  7. isValidURL(String urlString)
  8. isValidUrl(URI uri)
  9. isValidURL(URL url)