• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to mask credit card number (using regex?)

#21
[eluser]Rick Jolly[/eluser]
[quote author="Pygon" date="1194144678"]I'll let others continue the fluff from here on.[/quote]
Amen. All those forsaken AMEX users can now rest.

#22
[eluser]TheFuzzy0ne[/eluser]
Code:
$card_number = '1234-5678-9101-1121';
$card_number = 'xxxx-xxxx-xxxx-' . substr($cardnumber, 15);

Untested, but should work as expected. As credit card numbers are in a standard format, you don't need any regexes. That's just overkill. Instead, grab the part of the number you want, and append it to the mask.

#23
[eluser]jdfwarrior[/eluser]
Why show a masked cc # in the first place? It doesn't provide the user with any useful information. Why not just pull the last four digits and say 'I'm charging stuff to the card ending in 1234' as opposed to even dealing with the regular expressions and showing the X's? If you still really wanna do it, as long as its not a terribly inefficient way or doing it (to the point to where the is an obvious performance issue), do whatever way you want. Will the customer be picking through your code to see if they like the way you did it? No.

#24
[eluser]Unknown[/eluser]
this is very interesting. thanks for sharing


commission de surendettement - commission de surendettement, vous pouvez demander un dossier de surendettement.

#25
[eluser]Unknown[/eluser]
Cheers and we look forward to your Forum Favourites selections!


plan solution commission de surendettement - commission de surendettement, vous pouvez demander un dossier de surendettement.plan solution commission de surendettement

#26
[eluser]Unknown[/eluser]
I came up with a single regexp to mask all but the first and last four digits of a CC. This will also keep any non-numbers.

Code:
preg_replace('/(?!^.?)[0-9](?!(.){0,3}$)/', '*', '3456-7890-1234-5678')

Keeps the FIRST CHARACTER, the LAST FOUR CHARACTERS, and any NON-NUMERIC CHARACTERS in-between. Masks (*) everything else.

Code:
"3456-7890-1234-5678" = "3***-****-****-5678"
"4567890123456789" = "4***********6789"
"4928-abcd9012-3456" = "4***-abcd****-3456"
"498291842" = "4****1842"

If the regular expression is a bit confusing, (?!) is a "look-ahead not-equals", meaning make sure this does NOT come before or next, but leave it alone.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.