我试图检查URL是否有效或无效。第7、8个检查返回错误的输出结果。
alert('1: ' + learnRegExp('http://www.google-com.123.com')); // true
alert('2: ' + learnRegExp('http://www.google-com.123')); // false
alert('3: ' + learnRegExp('https://www.google-com.com')); // true
alert('4: ' + learnRegExp('http://google-com.com')); // true
alert('5: ' + learnRegExp('http://google.com')); //true
alert('6: ' + learnRegExp('google.com')); //true
alert('7: ' + learnRegExp('ww.google.com')); //false -> it returns true
alert('8: ' + learnRegExp('www.google.co.il')); //true -> it returns false
alert('9: ' + learnRegExp('http://ww.google.co.il')); //false
alert('10: ' + learnRegExp('https://ww.google.co.il')); //false
function learnRegExp(){
return /((ftp|https?):\/\/)?(www\.)?[a-z0-9\-\.]{3,}\.[a-z]{3}$/
.test(learnRegExp.arguments[0]);
}
请帮我解决这个问题。
感谢任何帮助!
www
只是一个子域名。我不会费心在正则表达式中明确包含它。 - David Sherrethttp://xyz.mysite.org.ru
。我想真正的测试是尝试加载它。 - Yuriy Galanterww.google.com
是一个有效的域名。 - sp00m.--.wkh
或者6-..oqw
但是会拒绝google.fr
。 - sp00m