Created
August 28, 2014 09:30
-
-
Save mistermark/19e54b3011174eaaf38f to your computer and use it in GitHub Desktop.
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
/** | |
* Format for a Credit Card | |
* @return {string} Formatted number | |
*/ | |
module.filter("creditcard", function() { | |
return function(str) { | |
if(typeof str !== "undefined"){ | |
var nums = str.substr(0,19).replace(/[^\d]/gi,""); | |
var r = nums.match(/(\d){4}/g); | |
r[1] = r[1].replace(/[0-9]/g, "*"); | |
r[2] = r[2].replace(/[0-9]/g, "*"); | |
r = r.slice(0,5); | |
if(r){ | |
var nStr = "", nums; | |
for (var i=0;i<r.length;i++){ | |
nStr += i != r.length-1 ? r[i] + ((i<3)?" ":"") : r[i]; | |
} | |
nums = (nums.length % 4 !== 0 ? nStr + " " + nums.substr((r.length * 4),nums.length) : nStr); | |
str = nums; | |
} else { | |
str = nums; | |
} | |
return str; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment