Credit card numbers formatting with javascript


credit card number
“0000 0000 0000 0000”

when creating a credit card form by using text fields:
Is there a way to automatically add spaces every 4 digits the user is typing
by using javascript?


It is, check the file – credit_card_input.rp (46.0 KB)

I just replaced spaces with “_” symbols to make them distinguishable in the actions.

P.S. It works only for typing, not for pasting.


I need a solution where the user can correct his input by using the delete key as well. In your solution, if the user uses the delete key he will get stuck half way.


credit_card_input_2.rp (54.7 KB)

now it works better


Works just perfect! Thanks a lot! :star_struck: