Created
April 20, 2016 17:28
-
-
Save ceautery/5b32a46ac4ed6c1df5d63281df90ccd9 to your computer and use it in GitHub Desktop.
Mask the middle part of credit card numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MiddleMasker(leadNumChars, trailNumChars, replaceChar) { | |
var re = new RegExp('(^.{' + leadNumChars + '})?.(?=.{' + trailNumChars + '})', 'g'); | |
this.mask = function(str) { | |
return str.replace(re, '$1' + replaceChar) | |
} | |
} | |
var m = new MiddleMasker(6, 4, 'X'); | |
m.mask('4111123456789012'); // "411112XXXXXX9012" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment