I have an input in my form that takes a credit card number.
<input type="text" class="form-control" name="CCnumber" ng-model="CCnumber" ng-blur="balanceParent.maskCreditCard(this)">
On blur, I'd like to mask the credit card input like so:
4444************
And then on focus, I'd like to return the original credit card number:
4444333322221111
Using ng-blur, I'm able to do simple javascript to return a masked input.
vm.maskCreditCard = function(modalScope) {
if(modalScope.CCnumber){
var CCnumber = modalScope.CCnumber.replace(/\s+/g, '');
var parts = CCnumber.match(/[\s\S]{1,4}/g) || [];
for(var i = 0; i < parts.length; i++) {
if(i !== 0) {
parts[i] = '****';
}
}
modalScope.CCnumber = parts.join("");
}
};
My problem is getting that number back once the user focuses on the input once more. Is there a way to preserve the inital value of the input while also masking it?