javascript - Insert character after every nth character -
this question has reply here:
how can insert character after every n characters in javascript? 2 answersi'm trying convert number like: 1215464565 12-15-46-45-65. i'm trying this:
var num = 1215464565; num = num.tostring(); num.replace(/(.{2)/g,"-1");
the jsfiddle, doesn't reflect alter though.
var num = 1215464565; var newnum = num.tostring().match(/.{2}/g).join('-'); console.log(newnum);
jsfiddle example
javascript regex
No comments:
Post a Comment