Wednesday, August 30, 2006

JS function for validating internet URL

I am posting this since most of the Regular Expressions I got from the NET where not working on
non-IE browsers..

function validate()
{

if (document.Form1.TextBox1.value!='')
{
var urlRegxp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
var url = document.Form1.TextBox1.value
if(urlRegxp.test(url) != true)
{
alert('Please enter a valid External URL');
document.Form1.TextBox1.focus();
return false;
}
}
}

Cheers
Rajesh Sivaraman.

No comments: