You need to sign in to do that
Don't have an account?
Pattern for a credit card number?
I wrote a trigger to check if certain fields contain credit card numbers when they are saved. If I find a credit card I will eliminate the digits from the first portion of the string and replace with a sequence of star characters (************0000). The code works fine in all test cases except when the credit card is entered with spaces between the digits (ie 0000 0000 0000 0000). I'm thinking that the only way to address this test case is with the Pattern & Matcher methods. However, I am not having any luck matching possible patterns within my code.
Does anyone have a pattern for checking credit card numbers that they would be willing to post here? I would greatly appreciate the assistance.
-greg
I hope you have found an answer by now, but just want to answer if other finds this blog post as I did. I have created two solutions for this that handles Visa, Mastercard and American Express cards. For handling of other cards as well, you can find credit cards bin ranges here, BIN List & Range for MasterCard, Visa, Amex +++ (https://neapay.com/post/bin-list-range-for-mastercard-visa-amex-diners-discover-jcb-cup_94.html).
The sample code assume that there are no more than one . or space for every 4 digits in the card number.
Alternative one, using Pattern, will mask the credit card number and show maximum the 6 first and 4 last digits. The other alternative replaces the credit card number with the text "<<possible CC number>>".
Sample Code in APEX:
Output: