File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How i can check an string to be a correct web site format? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How i can check an string to be a correct web site format?" Watch "How i can check an string to be a correct web site format?" New topic
Author

How i can check an string to be a correct web site format?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reading my post.
i want to check an string to see whether it is a correct web site name or not.
I know that i should use regular expression , but i do not know how i should do this , can some one help me with this ?

Thanks
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You could use a regular expression.

However, I think it would be better to try to construct a java.net.URL object from the String. If it its a valid URL, the construction will succeed. If it is badly-formed, the constructor will throw MalformedURLException.

That will be good enough to detect many common errors in your URL. However, you may wish to go further. If the java.net.URL object is successfully constructed, you can then check whether the protocol is appropriate for a Web site. You can check this with the getProtocol() method; the protocol should be "http". You could also check that a host has been given, by testing whether the getHost() method returns a non-null, non-empty string.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How i can check an string to be a correct web site format?