What is the best way to check if a URL is valid in Java?
If tried to call new URL(urlString)
and catch a MalformedURLException
, but it seems to be happy with anything that begins with http://
.
I'm not concerned about establishing a connection, just validity. Is there a method for this? An annotation in Hibernate Validator? Should I use a regex?
Edit: Some examples of accepted URLs are http://***
and http://my favorite site!
.