title: URL validation both in php and javascript
body: <p>I found lots of url validation method in this website and also in others. But i can not find the exact one that is required for my project. Here is what i need. </p>
  
  <pre><code>&lt;form name="example" value=""&gt;
   &lt;input type='text' name='link' /&gt;
  &lt;input type="submit" name="submit" id="submit" value="" /&gt;    
   &lt;/form&gt;
  </code></pre>
  
  <p>Now if someone type a link in the text field then i have to check whether the link is valid or not.
  Valid link will be like</p>
  
  <pre><code>1. http://www.example.com
  2. www.example.com
  3. example.com
  4. (some space) then one of the three links above
  5. one of the three links above then some space
  </code></pre>
  
  <p>These are the valid formats. Anything else is typed in the text field should give output invalid link</p>
  
  <p>I require the solution both in javascript and PHP. </p>