function formatCardNo(cardNo){
var result = [],len = cardNo.length;
var j = 0;
for(var i = 0 ; i < len;i++){
if(cardNo[i] == " "){
continue;
}
j++;
result.push(cardNo[i]);
if(j % 4 ==0 && i != len-1){
result.push(" ")
}
}
return result.join("");
}
原文:http://www.cnblogs.com/lglijing/p/3937967.html