Been having a conversation with a friend of mine and we're both stuck on a bit of JS and it's driving us both nuts:
[20:04:32] KCMCL (PS):I am tryin to validate a htlm -- but don't need to validate the http bit
[20:04:32] KCMCL (PS): the js is
[20:04:33] KCMCL (PS): function isUrl(s) {
var regexp = /((ftp|http|https):\/\/)?(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}
[20:04:39] KCMCL (PS): in php I can do this...
[20:05:03] KCMCL (PS): but in js, if I lose the http bit -- regardless, it will produce a false result
[20:05:08] KCMCL (PS): in php it does not
[20:05:24] KCMCL (PS): php is this
[20:05:25] KCMCL (PS): $url = "http://facebook.mafiawars.zynga.com/mwfb/index2.php?skip_req_frame=1&mwcom=1";
if (preg_match("/^(http(s?):\/\/|ftp:\/\/{1})((\w+\.){1,})\w{2,}$/i", $url)) {
echo "Valid URL";
} else {
echo "Invalid URL";
}
[20:05:39] KCMCL (PS): will create an invalid URL
[20:05:47] KCMCL (PS): as I say, who cares about the regx as such...
[20:05:58] KCMCL (PS): question is, why does it not work in js...
Anyone care to lend some knowledge to this, in short we're trying to validate a URL but without the need for the HTTP etc