title: Host name url regex in JavaScript
body: <p>I know there are many RegExs out there for URLs etc, but I'm really stumped as to why this one wont work. I'm trying to make sure a user's entry is a proper web site, allowing for either www or not.</p>
  
  <pre><code>var pattern = 
  /http(s?):\/\/                      (http:// or https://)
  (?:[a-zA-Z]+\.){0,1}                (0 or 1 instance of www)
  (?:[a-zA-Z0-9][a-zA-Z0-9-]+){1}     (1 instance of a domain name)
  (?:\.[a-zA-Z]{2,6})+/;              (1 or more instance of .com or .co.uk)
  </code></pre>
  
  <p>It works for the following testcases using pattern.test()</p>
  
  <ul>
  <li><a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a> -> true </li>
  <li><a href="http://stackoverflow.com">http://stackoverflow.com</a> -> true</li>
  <li><a href="https://stackoverflow.com">https://stackoverflow.com</a> -> true </li>
  <li>htts://stackoverflow.com -> false</li>
  <li>http:/stackoverflow.com -> false</li>
  </ul>
  
  <p>However, even though I explicitly tell the regex it must match the .com or .co.uk, etc. it allows me to write such nonsense as:</p>
  
  <ul>
  <li><a href="http://www.stackoverflow">http://www.stackoverflow</a> -> true (wrong)</li>
  <li><a href="http://www.stackoverflow">http://www.stackoverflow</a>. -> true (wrong)</li>
  <li><a href="http://www.stackoverflow.c">http://www.stackoverflow.c</a> -> true (wrong)</li>
  </ul>
  
  <p>I've been wracking my brain trying different combos but I can understand why even though I explicitly say there must be one or more domain extension, that portion doesn't seem to matter?</p>
  
  <p>Cheers</p>