Jump to content

[FYI] Automatically put 'spaces' for credit/debit card inputs.


Recommended Posts

This is a quick tutorial on how to format user input for credit/debit cards.

First, we would need to add Header & Footer on your submission form and uncheck HTML editor. Once, done kindly put the code below inside the Footer.
 

<script>
var input = document.getElementById("textfield_ID");
var ctr = 0;
input.unsafe = function () {

    var key = event.keyCode || event.charCode;
    
    if (key == 8 || key == 46){
        if(input.value.length > 0){
            ctr = input.value.length-1;
        }
    }
    else {
        ctr = input.value.length+1;
        if(((ctr % 5) == 0) && ctr <19){
            input.value += ' ';
        }
    }
}
</script>


Once that is done, don't forget to set the maximum character limit for your Credit/Debit card field to 19. 

image.png.b0beebf79ee355251c2f98f7bbc206b7.png

This should result to something like this:

image.png.9744388d1e48800ea0b713a2662c05c4.pngimage.png.f3d02ca76877349bc594cac7b1410fc7.png

 

image.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...