Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Url validation

807605Sep 10 2007 — edited Sep 10 2007
Hello everybody...

There seems to be a serious problem...
In the application I need to check out whether an user input a valid/invalid/unavailable URL.....

When an user inputs say, http://www.yahoo.com
It show the right result ... Valid URL

But when an user input say www.yahoo.com
It show the result ... Invalid URL.

It means it needs the http:// to be included with the www,

What should I do so that an user need not enter the whole of http://www.yahoo.com but just www.yahoo.com

The code which I used was:
try 
             {
                  new URL(url).openStream().close();
                  // good
             }
             catch (MalformedURLException ex) 
             {
                  // invalid
                  checkURL=1;
             }
             catch (IOException ex) 
             {
                  //unavailable
                  checkURL=2;
             } 
Please help me.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2007
Added on Sep 10 2007
10 comments
619 views