I'm trying to format on the fly a string containing an American Express card number using a regular expression. It should have the following format 3400 000000 00009
.
What I found around here is the following:
var ccFmt = ccNum.replace(/\b(\d{4})(\d{6})(\d{5})\b/, '$1-$2-$3');
But this is useful when we have the entire string and we want to transform it. I want to do it on the fly, as the user type in a input field (make a space after first 4 chars, then another space after another 6 chars).
Any ideas how I can handle this ?