This php masking function will allow first and the last 4 digits for any credit card number. You can also provide the masking letter.
Credit card number has to be at least 13 character long.
function mask_cc($cc_num, $mask_ch='*') { if( strlen($cc_num) < 13) return $cc_num; else return preg_replace('/(?!^.?)[0-9](?!(.){0,3}$)/', $mask_ch, $cc_num); }
This is how you can call it.
mask_cc('1234123412341234', '#'); mask_cc('1234-1234-1234-1234', '*');