Mask all but last four of credit card

Anyone know how to mask all but last four of a credit card (or any datatype field) in a form?

Depends on what you want to do. With substr you can strip the last 4 postions, add * to it and display.

I am able to do this from MYSQL CLI and in Naviacat but SC is not working with it. Could you show me a simple example and where to put it in a form for a field?

I assume you want to extract the data from the table and present it on the form? Safest way is to create 1 new field on your form and make the cc field invisible. then in the onload event of the form you get something like:

$string={creditcard};
{mynewfield}=’***’.$string[strlen($string)-4];

I just got it to work with this.
SELECT
CONCAT(
REPEAT(‘X’, CHAR_LENGTH(cardnumber) - 4),
SUBSTRING(cardnumber, -4)
) AS test1
FROM ccard_payments
WHERE payment_id = ‘{payment_id}’

In the Grid Lookup of a new blank field with Label ticked.
Thank you for your input. I need to also try to make your way work which I have yet to get it to.

There’s nothing wrong in your solution. Only argue against it might be that it might not be supported in every database.

I got your solution working with this:

$string={cardnumber};
{card_number}=‘XXXX-XXXX-XXXX-’.$string[strlen($string)-4].$string[strlen($string)-3]
.$string[strlen($string)-2].$string[strlen($string)-1];

I really wanted to do this with event so I could enhance with if/else according to logged in user privilege.
I am now also using this on form that has SSN number but when no SSN exists, it throws error.

Thank you so much for the solution!