As you had specified the input string as "12345678901234" and expecting it to convert into "123-456 7890 1234", i had written the above code as per this requirement. If you are not aware of the exact number what customer is entering then above doesn't work, as the above code just returns the same string if it is less than or more than 14 characters.
In this case you need to find the pattern how the numbers need to be displayed and write your logic accordingly to construct the string based on length/
In this case you can write the function take the input string and return the formatted string in this function by using the above java code in it. This function you can use while setting the CardNumber value in data transform.