I am writing a application using JQuery in which I included my script in the head section of the webpage and the data of the page is dynamic and comes from the database.
Now I need to detect the URLs on the page. It can be an anchor tag or a simply a written URL.
For detecting an URL I am using this function
function checkURL(value) {
var urlregex = new RegExp(
"^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){0,1}([0-9A-Za-z]+\.)");
if(urlregex.test(value))
{
return(true);
}
return(false);
}
It works fine but if a URL doesn't have a www
prefix then it fails e.g. myweb.com
Please suggest a better regex for my code which works fine with all valid URLs including sub domains.
Can you also suggest a best way to detect URLs on my webpage?