I need to flag a textarea that contains a URL starting with http://, but not with https://. I thought this should work, but I'm getting the alert even when all URLs are https.
$('#template_form').submit(function() {
alert("this is the text: " + $("#template_data").val() );
val = $("#template_data").val();
if (val.search(/^http:\/\//)){
alert("there's a URL in there...");
return false;
}
return true;
});
<textarea id="template_data">This is a test of the new URL validation. Let's add a link to https://www.test.com</textarea>
This should only present the second alert if the URL were http://www.test.com, but it's throwing it even as is, with https://. What am I doing wrong?
searchreturns -1 for no match, which evaluates to true.regexp.test(string).