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!
.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…