mask a credit card javascript mdn
function maskify(cc) { return cc.replace(/.(?=.{4})/g, "#"); }
Here is what the above code is Doing:
1. Replace all but the last four characters with #
2. The regex /.(?=.{4})/g is a positive lookahead. It will match any character (.) that is followed by four characters (.{4}).
3. The g flag is used to perform a global match (find all matches rather than stopping after the first match).