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