javascript url validation help [closed]
If user enters a URL, as soon as they have completed the URL and hit enter the URL will appear below the text box and the text box will be emptied again.
It will only do this if it is a validly formed URL. For example if
someone writes blahbla.243
, this will not do
anything as it is not a valid URL.
It will, however, accept any variations that are valid
such as http://www.url.com
or www.url.co.uk
and
url.com.au
.
And it will remove anything after
the end of the country code for example if
the person types www.abc.net/dlkjfk
then
only www.abc.net
will be accepted.
Thank you!
This may not be as strict as you're looking for, but it's what I use and its decent
var reg = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
if(reg.test(elem[i].value) == false) {
//not cool story
}else{
//good link
}
精彩评论