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..
精彩评论