Mask 16 digit credit card but not 20 digit numbers

deepaltrivedi
Mega Contributor

Hi All - We have a change in requirement where we want to mask 16 digit credit card information in inbound email body but not 20 digit numbers as they are not credit card. I've below script that works perfectly but it masks any number over 12 digits -- i don't want to mask 20 digits number.

 

Thoughts on how i need to modify the bolded portion??

 

(function executeRule(current, previous /*null when async*/) {
var emailVars = [current.body,current.subject,current.body_text];
var arr = [];
for(e = 0; e < emailVars.length; e++) {


var wt = emailVars[e].match(/(https:\/\/.*wetransfer\.com)(.*)[^\s]/g);
var matches = emailVars[e].match(/(https:\/\/.*wetransfer\.com)(.*)[^\s]|([\d]){4}([ -])?([\d]){4}([ -])?([\d]){4}([ -])?([\d]){4}/g);
if(matches){
for(var i = 0; i < 16; i++) {
if(!wt || matches[i] != wt[0]) {
var numCount = 0;
var maskedCredCard = '';
for(var j = 0; j < matches[i].length; j++) {
if(matches[i][j] == '-' ||matches[i][j] == ' '|| numCount >= 12) {
maskedCredCard += matches[i][j];
}
else if(numCount < 12) {
maskedCredCard += '*';
numCount++;
}
}
if(e == 0) {
current.body = current.body.replace(matches[i] ,maskedCredCard);
}
else if(e == 1) {
current.subject = current.subject.replace(matches[i] ,maskedCredCard);
}
else if(e == 2) {
current.body_text = current.body_text.replace(matches[i], maskedCredCard);
}
} //closes WT if statement
}//closes matches for loop


} //closes if there are matches
} //closes loop through email variables
})(current, previous);

1 ACCEPTED SOLUTION

Hi,

 

Replace this below line and check

var numbers = email_body.match(/\d+/g).map(Number);

WITH

var numbers = email_body.match(/\s\d+/g).map(Number);

View solution in original post

26 REPLIES 26

Facelesss
Kilo Explorer

Asifnoor Thank you very much! I also considered how to accomplish it, and your assistance was very appreciated.

Alienka
Kilo Contributor

Asifnoor Thank you! I also thought how to do it helped me your thanks. Now everything is correct. It came in handy for me after I found additional earnings, which I found an article https://wealthynickel.com/how-to-make-an-extra-1000-a-month/, which tells how to earn an extra 1000 a month. With a part-time job, you can find more free time and spend more time with your family.