Javascript String toCardFormat()

Description

Javascript String toCardFormat()



String.prototype.toCardFormat = function () {
    return this.replace(/[^0-9]/g, "").substr(0, 16).split("").reduce(cardFormat, "");
    function cardFormat(str, l, i) {
        return str + ((!i || (i % 4)) ? "" : "-") + l;
    }//w  w w . j  a va  2  s  .  co  m
};



PreviousNext

Related