Javasript - Url validation
Posted: Tue Nov 09, 2004 1:54 pm
Does anyone have a ready code to validate if the given string is a valid url ?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
var expression2 = new RegExp("^(((ht|f)tp(s?))\://)?(www.|їa-zA-Z].)їa-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|fi)(\:ї0-9]+)*(/($|їa-zA-Z0-9\.\,\;\?''\\\+&%\$#\=~_\-]+))*$", "i");Code: Select all
var expression2 = new RegExp("^(https?\://)?їa-zA-Z0-9-]+\.(їa-zA-Z0-9-]+\.?)+/?($|їa-zA-Z0-9\.\,\;\?''\\\+&%\$#\=~_\-]+)$", "i");Code: Select all
function checkURL(url)
{
var expression = new RegExp("^(http://)?їa-zA-Z0-9-]+\.(їa-zA-Z0-9-]+\.?)+/?($|їa-zA-Z0-9\.\,\;\?''\\\+&%\$#\=~_\-]+)$", "i");
if (expression.test(url))
return true;
else
{
alert( "Kotisivun osoite ei ole oikein.");
return false;
}
}