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.

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 += ' ';

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


This should result to something like this:




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.

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.

  • Create New...