by php developer on August 28th, 2008, 9:01 am
Here is a javascript function to validate the format of a URL. It is based on a regular expression to check the url format.
- Code: Select all
function validateUrlFormat(sUrl)
{
var sRegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
if(sRegExp.test(sUrl))
return true;
return false;
}