Saturday, April 30, 2016

AX how to masking credit card numbers using x++ code

Str LSF_AccMask(Str _accountNumber)
{
    TextBuffer buffer = new TextBuffer();
    int i;
    str accChar, accMasked, accFree;
    ;

    for(i=1; i<=strlen(_accountNumber); i++)
    {
        accChar = substr(_accountNumber,i,1);
        buffer.setText(accChar);
        buffer.replace(accChar, "*");
        accFree = (i<=strlen(_accountNumber)-4) ? buffer.getText() : accChar;
        accMasked = accMasked + accFree;
    }

    return(accMasked);
}