我有一根绳子:"快速的棕色狐狸跳过懒狗."
我想使用javascript(可能使用jQuery)每n个字符插入一个字符.例如,我想打电话:
var s = "The quick brown fox jumps over the lazy dogs.";
var new_s = UpdateString("$",5);
// new_s should equal "The q$uick $brown$ fox $jumps$ over$ the $lazy $dogs.$"
Run Code Online (Sandbox Code Playgroud)
目标是使用此函数插入并调整长字符串以允许它们换行.也许有人知道更好的方法?
如何在键入时格式化并验证每个4位数之间带有空格的信用卡号:
eg: 4464 6846 4354 3564
Run Code Online (Sandbox Code Playgroud)
我试过了:
$('.creditno').keyup(function() {
cc = $(this).val().split("-").join("");
cc = cc.match(new RegExp('.{1,4}$|.{1,4}', 'g')).join("-");
$(this).val(cc);
});
Run Code Online (Sandbox Code Playgroud)
请帮忙