我有這樣的(從輸出的console.log)數組:的jQuery +檢查一個數組只包含IP不會忽略
["122.42.123.1", "122.42.123.1", "122.42.123.1", "awdawd", "awdawd"]
我怎麼能檢查它是否只包含IP地址,如果是這樣return true
?並且,如果它不(像上面的例子)return false
?
我都試過,我發現這裏和谷歌(like this one),並在每個循環中使用它們不同的功能,但是,這並不工作:
//Get ip list from a textarea (each row = 1 ip)
var content = $("#banUList").val();
var ips = content.split("\n");
console.log(ips);
$(ips).each(function(){
if(checkFunction($(this)) == false){
//Wrong
}else{
//correct
}
});
如果可能的話,我想避免這個循環在全部,並有一個功能,檢查整個陣列的任何不是IP的var
。不管有多少vars
。
不能避免'for'循環,但你可以阻止它,當它找到一個錯誤的IP與'break' – DoubleYo