- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 02:28 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 03:24 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 02:37 AM
Hi @SAS21,
Just to make things a little clearer, can you provide an example of both a valid and non valid card number please.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 03:05 AM
Hi Robbie ,
Here is the code i am trying
var testcases = 'a3711111111111\na37222222222222\n3711 11111 1111\n3711---11111-1111\nMycardnumberis373737373737373\nThis should not match: 1234567812345';
var matches = testcases.match(new RegExp('(?:^|(?<=[^0-9]))37(?:[ \t-]*\\d){13}', 'gj'));
gs.info('Test Cases:\n' + testcases + '\n');
gs.info('Matches:');
for(var i in matches)
gs.info(matches[i]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 03:21 AM
Hi @SAS21,
Thanks for providing the script. Running it via a background script the match appears on "373737373737373"currently.
What I was after was explicit examples of what are valid card numbers where you want the match, and examples where it should not match.
For example:
- "A12345678901234" - Should this match? (15 chars in total of which after the initial letter, 14 numbers follow)
- "A123456789012345" - Should this match? (16 chars in total of which after the initial letter, 15 numbers follow)
- "AB123456789012345" - Should this match? (17 chars in total of which after the initial letter, 15 numbers follow)
I assume spaces and other 'special characters' are not allowed. Please confirm the above as to which ones are valid and if spaces / special chars are not allowed.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2024 02:38 AM