Credit card numbers formatting with javascript


#1

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?


#2

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.


#3

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.


#4

credit_card_input_2.rp (54.7 KB)

now it works better


#5

Works just perfect! Thanks a lot! :star_struck: