Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify if a String in Java is a valid URL

Tags:

java

url

How can I check if a string is a URL in Java?

like image 666
lacas Avatar asked Oct 14 '10 09:10

lacas


People also ask

How do you check if a string is a valid URL in Java?

Using java.net.url url class to validate a URL. The idea is to create a URL object from the specified String representation. If we do not get exception while creating the object, we return true. Else we return false.

How do you determine if a string is a URL?

HTMLInputElement. checkValidity() method is used to check if a string in <input> element's value attribute is URL . The checkvalidity() method returns true if the value is a proper URL and false if the input is not a proper URL.

Is valid URI Java?

For a URI to be valid, you only have to verify it against this syntax. Connecting to it verifies that a server is registered for and listening to that URI which 1. is an entirely separate condition from the validity of the URI itself, 2.

How do I know if my string is URL fluttering?

To check Valid URL string you just have to use Uri. parse() like below. This also returns true for string "http:". There is also Uri.


1 Answers

You can try to create a java.net.URL object out of it. If it is not a proper URL, a MalformedURLException will be thrown.

like image 179
Grodriguez Avatar answered Sep 26 '22 00:09

Grodriguez