Reputation: 2441
is there any way to mask the output of the input field once passed to the next page
Enter Card : 123456789011
after the data has been passed onto the next page when displayed it should look like this
Card info: ********9011
the first 8 digits was converted to asterisk and the last 4 digits of the card is visible.
Upvotes: 0
Views: 329
Reputation: 2468
If you've already ensured that the card number is a valid length:
card = "123456789011";
output = "********" + card.substring(card.length-4);
is all you'll need. Output will now be as you wanted, and although Starx's answer is dynamic: it's also overkill.
Upvotes: 1
Reputation: 78981
Something like this
var card = "123456789011";
var str = "";
//Create the "*" for exactly 4 digits short
for(var i=1; i <= card.length-4; i++) {
str += "*";
}
//Join the asterisk and last 4 characters
ecard = str + card.substr(card.length-4);
console.log(ecard);
Upvotes: 0