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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -