Archive for May, 2010

URL Validation in JavaScript

This won’t catch every malformed URL, but it’s a pretty good filter:
function test_url(url) {
// comments:  (protocol )(user&pass  ) (subdomains&domain) (TLD            )(port   ) (path & query string   )
var regex = /^https?:\/\/(\w+(:\w+)?\@)?([\w\-]+|\.[\w\-]+)+(\.[a-zA-Z]{2,6})(:[0-9]+)?(\/[\w#!:.?+=&%@!\-\/]*)?$/i;
return url.match(regex);
}

Read the rest of this entry »