title: regex detect url and prepend http://
body: <p>I would like to detect url's that are entered in a text input. I have the following code which prepends <code>http://</code> to the beginning of what has been entered:</p>
  
  <pre><code>var input = $(this);
  var val = input.val();
  if (val &amp;&amp; !val.match(/^http([s]?):\/\/.*/)) {
      input.val('http://' + val);
  }
  </code></pre>
  
  <p>How would I go about adapting this to only append the <code>http://</code> if it contains a string followed by a tld? At the moment if I enter a string for example:</p>
  
  <pre><code>Hello. This is a test
  </code></pre>
  
  <p>the <code>http://</code> will get appended to hello, even though it's not a url. Any help would be greatly appreciated.</p>