开发者

javascript url validation help [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For开发者_如何学Go help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜