The CreatorCon Call for Content is officially open! Get started here.

Regex is not working as expected

SAS21
Tera Guru

Regex should mask if the card number is exactly 15 digits(including the first two)  - not less than that not more than that

Here is the regex 

var matches = testcases.match(new RegExp('(?:^|(?<=[^0-9]))37(?:[ \t-]*\\d){13}', 'gj'));

 

but the above is masking the number that has 16 digits as well.

 

Appreciate the Help

 

1 ACCEPTED SOLUTION

Jitendra Diwak1
Kilo Sage

Hi @SAS21

 

Here is below code for the same. 

 

var matches = testcases.match(new RegExp('(?:^|(?<=[^0-9]))37(?:[ \t-]*\\d){13}(?![0-9])', 'gj'));

 

Please accept my solution if it resolves your issue and thumps 👍 up 

 

Thanks 

Jitendra 

Please accept my solution if it works for and thumps up.

View solution in original post

7 REPLIES 7

Jitendra Diwak1
Kilo Sage

Hi @SAS21

 

Here is below code for the same. 

 

var matches = testcases.match(new RegExp('(?:^|(?<=[^0-9]))37(?:[ \t-]*\\d){13}(?![0-9])', 'gj'));

 

Please accept my solution if it resolves your issue and thumps 👍 up 

 

Thanks 

Jitendra 

Please accept my solution if it works for and thumps up.

Thank you Jitendra!

Community Alums
Not applicable

Hi @SAS21 ,

I tried your problem in my PDI and it works for me please check below code 

var paragraph = '123456781234512';
var regex = /^(?=(?:\d\D*){1,15}$)\d+(?:[.,]\d+)?$/g;
var found = paragraph.match(regex);

gs.log("Fount = " + found);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak