Identify the card data and print a message not working as expected

SAS21
Tera Guru

Hi, 

trying to check the pattern for the card data that has total 15 digits and always starts with eg: 27 . User can input the card data in any of the following formats (like with - or with space or without space )  2755-051007-81973 or 2755 051007 81973 or 275505100781973. Have to look for these formats in the text field and print the message. 

Was trying through the fix script with the sample text like below.

var sampleText = " Work notes should not have sensitive information. Eg data formats are 2755-051007-81973 or 2755 051007 81973 or 275505100781973.";
var pattern = /^27(?:\d{4}-\d{6}-\d{5}|\s?\d{4}\s?\d{6}\s?\d{5}|\d{15})$/;
var result = pattern.test(sampleText);
gs.info(result );
if(result ){
    gs.info('sample text has card data');
}
 
output is coming as false.is there something wrong with the regex pattern? Appreciate the help!
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @SAS21 ,

 

Try this code

var sampleText = " Work notes should not have sensitive information. Eg data formats are 2755-051007-81973 or 2755 051007 81973 or 275505100781973.";
var pattern = /27\d{2}[\-\s]?\d{6}[\-\s]?\d{5}/g;
var result = sampleText.match(pattern);
gs.info(result);
if(result) {
    gs.info('sample text has card data');
}

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

View solution in original post

8 REPLIES 8

Community Alums
Not applicable

Hi @SAS21 ,

 

Try this code

var sampleText = " Work notes should not have sensitive information. Eg data formats are 2755-051007-81973 or 2755 051007 81973 or 275505100781973.";
var pattern = /27\d{2}[\-\s]?\d{6}[\-\s]?\d{5}/g;
var result = sampleText.match(pattern);
gs.info(result);
if(result) {
    gs.info('sample text has card data');
}

 

I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

thank you sai. If we have to mask only the first 4 digits how can we implement that ?

Hello Sai, 

 For Eg: if i have the data as follows , 27-5506-1006-81965. Is it possible to get the output as xx-xx06-1006-81956. Can we have the format of the data as it is and mask the 4 digits ? 

 

Community Alums
Not applicable

@SAS21 

 

Have you tried the code in my previous response? I have provided the code to mask first 4 digits