I am trying to use a regular expression that identifies URLS. I have taken it from: Check if a Javascript string is a url and its code is:
function ValidURL(str) {
var pattern = new RegExp('^(https?:\/\/)?'+ // protocol
'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
'((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
'(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
'(\?[;&a-z\d%_.~+=-]*)?'+ // query string
'(\#[-a-z\d_]*)?$','i'); // fragment locater
if(!pattern.test(str)) {
alert("Please enter a valid URL.");
return false;
} else {
return true;
}
}
whenever i send the following WRONG URL: "http://www.pinevalleyscountrycreations.com/sitebuildercontent/sitebuilderpictures/ .gif"
to go through this code my browser freezes for a few minutes but following the freeze it returns a true value.
any ideas on what is missing in the regex's defenitions for both of the problems? the freeze and the wrong return value?
Thanks in advance!