JavaScript RegEx format string containing American Express card number -


i'm trying format string containing american express credit card number using regular expression. here's i'm using visa, mastercard , discover number formatting, doesn't work american express:

var formatvisamastercarddiscover = function (     number) {     return number.split(/(?=(?:\d{4})+($))/).filter(function (         n) {         return (n != "");     }).join("-"); }; 

so, i'm curious regular expression amex number be. format should {4}-{6}-{5}. i'd appreciate because couldn't find while searching except how validate not want. want format it.

you can use:

var ccnum = '341256789012345';  var ccfmt = ccnum.replace(/\b(\d{4})(\d{6})(\d{5})\b/, '$1-$2-$3'); //=> 3412-567890-12345 

regex demo


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -