Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

masking credit card & bank account information

I'm looking for a php function which can mask credit card & bank information such as routing number and account numbers. I need to mask many formats, so the existing stack overflow answers don't help me that much.

So for example, if the input is 304-443-2456, the function should return xxx-xxx-2456. Sometimes the number has dashes, and can be in various lengths.

I'm looking for something generic, that I can extend as needed, preferably a zend framework view helper class.

like image 718
aporat Avatar asked Oct 10 '11 20:10

aporat


People also ask

What is card number masking?

When you use a masked credit card number, you get a new, unique credit card number with an expiration date and security code. This new number gets linked to your normal credit card account, but the seller never sees your real card details.

How do you mask a credit card charge?

Use an online payment service. Purchases you make through online payment services, such as PayPal or Google Pay will show up on your bank or credit card statement as the name of the payment service. This can help mask your surprise purchase by hiding the retailer you purchased from.

What is masked debit card?

PAN masking hides a portion of the long card number, or PAN, on a credit or debit card, protecting the card account numbers when displayed or printed. DTMF masking is used in specific technology when a customer enters their card details over the phone.


1 Answers

Some little regex in a function of it own, configuration available:

$number = '304-443-2456';

function mask_number($number, $count = 4, $seperators = '-')
{
    $masked = preg_replace('/\d/', 'x', $number);
    $last = preg_match(sprintf('/([%s]?\d){%d}$/', preg_quote($seperators),  $count), $number, $matches);
    if ($last) {
        list($clean) = $matches;
        $masked = substr($masked, 0, -strlen($clean)) . $clean;
    }
    return $masked;
}

echo mask_number($number); # xxx-xxx-2456

If the function fails, it will return all masked (e.g. a different seperator, less than 4 digits etc.). Some child-safety build in you could say.

Demo

like image 80
hakre Avatar answered Sep 29 '22 05:09

hakre