Validating a URL
From Unofficial Konfabulator Wiki
This function validates a URL using regular expressions. You can specify the prefixRequired parameter (set it to true) to force the function to only accept URLs starting with http://, https://, or ftp://, otherwise this prefix will be optional.
function isUrl(str, prefixRequired) { strExp = '^(((http(s?))|(ftp))\:\/\/)'; if (arguments.length == 1 && arguments[1] != false) strExp += '?'; strExp += '(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(\.[a-z]{2,4})' + '(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$'; objRegExp = new RegExp(strExp); return objRegExp.test(str); }
