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:

Hi there @adverico, I tried using your file to add spaces to my card input field but for some reason it isn’t working.

I have set up “Input card number” as a phone number field so that mobile can bring the num pad and have set the max length to 19. I thought maybe that is the problem but changing those to match your example didn’t work.

Not sure how to fix it :confused:

I hope you can help.

Thanks!

Payment-method_UK.rp (206.5 KB)