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

Have you tried Encrypted Fields? Contact Salesforce Support and have them turn it on for you -- I think it might do what you're looking for even without any trigger.
The issue is that users are entering credit card numbers into various fields and shouldn't be. The encrypted fields is a valid idea but we are trying to prevent users from entering credit card numbers at all - the policy is that no credit card details should be stored in the app and I am simply trying to enforce this policy using a trigger.
-greg

Well, why not do a replace or replaceAll on all dashes and spaces in there, replacing them with nothing, and then run that preprocessed string through your filter? That should cover it.
The original code that I wrote was flawed in that it was looking for spaces between the various sub-strings to determine where credit cards may or may not begin/end in my text fields. This processing was causing me to miss valid credit card numbers that had spaces between the digits and I thought that the only way to remedy the problem was by using the pattern/matcher methods.
It turns out that I was able to alter my logic to look for sequences of numbers while ignoring the separators between number characters (specifically the white space). My code now works for all test cases so I will not be needing any credit card patterns. Werewolf - although I wasn't able to make use of any of your suggestions, I do appreciate your responses.
-greg