This discussion is archived
10 Replies Latest reply: Sep 10, 2007 6:13 AM by DarrylBurke RSS

Url validation

807605 Newbie
Currently Being Moderated
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.