开发者

Javascript regex to detect http://www.google.fr

I'm new at using Javascript regexp and after severa开发者_JS百科l failed attempts I'm still wondering how to check if an URL starts with http://www.google.fr


var url = "http://www.google.fr";
if(url.match(/^http:\/\/www\.google\.fr/))
    alert("It matches!");

But you might want to allow more variations of the address, and it's also important to check that what follows it is something valid, so you don't match things like http://www.google.fr-h4xx0r.com

Eg: /^http:\/\/(?:www\.)?google\.fr(?=\/|$)/i


try this

var url_reg         = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜