我想喜欢“http://www.google.com”的具体URL在JavaScript如何在JavaScript或jQuery中匹配特定的URL?
匹配var str = "http://wwww.google.com"
var test = match(str)
if(test) {
alerT(match with the url)
}
请建议我该怎么做。
我想喜欢“http://www.google.com”的具体URL在JavaScript如何在JavaScript或jQuery中匹配特定的URL?
匹配var str = "http://wwww.google.com"
var test = match(str)
if(test) {
alerT(match with the url)
}
请建议我该怎么做。
它可以是http
或https
,所以最好以验证两个步骤的网址:
var str = "http://www.google.com";
var protocol = str.match(/http/gi);
if (protocol != null){
var url = str.match(/wwww.google.com/gi);
if(url != null){
//Do your work
}
}
请考虑添加一些文字来解释你的答案。 – GibboK
如果要测试变量是否与特定网址匹配,可以使用简单表达式。
var str = "http://wwww.google.com";
if(str == "http://wwww.google.com"){
alert('string matches');
}
请添加说明以解决这个问题。 [answer] –
有哪些有效/无效的网址吗? –