i got a jQuery function to check a textarea for “valid” urls while someone is typing.
$(".url2").keyup(validNum).blur(validNum);
function validNum() {
var initVal = $(this).val();
outputVal = initVal.replace(/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])$/,"replace this link by bla..");
if (initVal != outputVal) {
$(this).val(outputVal);
}}
});
problem is, that the functions already replaces the url as soon as “http://www.ab” is typed instead of waiting till space is pressed (complete url, waitig for space, replace with this function). I want to achieve, that people can type in a whole url like http://www.example.org/site?id=1&etcetc before it gets replaced. So I think of “space” as a trigger to start the function. Can someone help me or someone got a better idea?
Thank you so much
wordi
If you want space or whitespace chars to trigger validation, use this: