Skip to content

Instantly share code, notes, and snippets.

@neilbo
Created September 10, 2014 03:59
Show Gist options
  • Save neilbo/4863235b7f06017f7ee0 to your computer and use it in GitHub Desktop.
Save neilbo/4863235b7f06017f7ee0 to your computer and use it in GitHub Desktop.
Mask Credit Card xxx-xxxx-xxxx-4567
app.filter('creditcard', function(){
return function(cc, maskChar, sep){
if(!sep)
sep = '-';
var maskedNum = Array(cc.length - 3).join(maskChar) + cc.substr(cc.length - 4, 4);
maskedNum = maskedNum.substring(0, 4) + sep +
maskedNum.substring(4, 8) + sep +
maskedNum.substring(8, 12) + sep +
maskedNum.substring(12, 16);
return maskedNum;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment