URL Validation Function

This section contains a lot of Scripting material for your website.

URL Validation Function

Postby 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;
}
php developer
 
Posts: 25
Joined: July 25th, 2008, 4:56 am

Return to Java Script / VB Script

Who is online

Users browsing this forum: No registered users and 0 guests