sneakyimp
02-14-2008, 02:17 PM
I have written this URL validator function in Javascript:
function checkURL(sURL) {
var re = new RegExp("^(http:\/\/|https:\/\/|www\.|//)(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)*$", 'i');
return sURL.match(re);
}
Although there is not a single spaces in my regular expression, it will return true for a url containing spaces like "http://foo bar.com". It looks to me like I have properly escaped all the periods so they don't match just anything. Can anyone help me figure out what the problem is?
function checkURL(sURL) {
var re = new RegExp("^(http:\/\/|https:\/\/|www\.|//)(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)*$", 'i');
return sURL.match(re);
}
Although there is not a single spaces in my regular expression, it will return true for a url containing spaces like "http://foo bar.com". It looks to me like I have properly escaped all the periods so they don't match just anything. Can anyone help me figure out what the problem is?