Javasript - Url validation
Moderator: General Moderators
-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am
Javasript - Url validation
Does anyone have a ready code to validate if the given string is a valid url ?
-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am
Found one with cryptic REGEXP
Could someone clean the crap out of this:
I'd like it to have just
[http(s)://][something]
with the legal characters.
Could someone clean the crap out of this:
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");[http(s)://][something]
with the legal characters.
something like this (untested).
Code: Select all
var expression2 = new RegExp("^(https?\://)?їa-zA-Z0-9-]+\.(їa-zA-Z0-9-]+\.?)+/?($|їa-zA-Z0-9\.\,\;\?''\\\+&%\$#\=~_\-]+)$", "i");-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am
REGEXP seems fine (http://www.regexlib.com/Search.aspx?k=url%20validate) But i can't get my javasript working. Nothing seems to match.
Wait. I gave it a wrong parameter...
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;
}
}-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am