开发者

Identify URLs in a textarea and show them as output using javascript

开发者 https://www.devze.com 2023-01-13 08:13 出处:网络
i have a text area and a click me. In that text area, if a user enters some URLs then the input should be marked invalid on the button click.

i have a text area and a click me. In that text area, if a user enters some URLs then the input should be marked invalid on the button click.

For example, if my input is

"StackOverFlow, the greatest codding buddy you could ever have. The URL: www.stackoverflow.com You can also checkout meta.stackoverf开发者_JAVA百科low.com which is also super cool"

At button Click the error should be.

"Form submit failed, because you have entered some URLS. The URLs are

- www.stackoverflow.com

- meta.stackoverflow.com"

I would like a pure javascript solution. No jquery please.


Took one of those regex from the link below: http://regexlib.com/Search.aspx?k=URL

Then :

var input = document.getElementbyId(id_of_your_form);
var x = input.match(/reg_ex_here/g);
if (x.length>0)  { // x[i] will hold the url
  var urls=x.concat();
  alert(urls);
}

It's not properly tested ... but hope you get the idea..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号