I'm looking to split a credit card number in 4 groups with 4 digits each.
So for 4111111111111111, to be displayed as 4111 1111 1111 1111.
Keep in mind that this code is already existing, so I don't want to split it while typing.
Thanks a lot!
I'm looking to split a credit card number in 4 groups with 4 digits each.
So for 4111111111111111, to be displayed as 4111 1111 1111 1111.
Keep in mind that this code is already existing, so I don't want to split it while typing.
Thanks a lot!
With simple logic
'4111111111111111'.match(/.{1,4}/g)
Other way
var str = '4111111111111111';
var parts = [];
for (var i = 0; i < str.length; i += 4) {
parts.push(str.substring(i, i + 4));
}
console.log(parts);