Below is my html page and script at the bottom of the html page.
The regex thing does not seem to work.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="">
<p>Input something in the input box:</p>
<p>Name : <input type="text" ng-model="name" placeholder="Enter name here"> </p>
<h1>Hello {{name}}</h1>
</div>
</body>
<script>
//below is the format obtained from the db
var format="##,##,###";
var reverseFormat=Array.from(format).reverse().join('');
var reverseFormatLength=reverseFormat.length;
//below are various separator
var firstseparator=null;
var restSeparator=null;
var firstSeparatorIndicator=0;
var indicesForVariousSeparators=[];
var number='123456524578';
x=number.toString();
var stringToGoIntoTheRegex=2;
var regex = new RegExp("\B(?=(\d{"+ stringToGoIntoTheRegex+"})+(?!\d))" , "g");
var lastThree = x.substring(x.length-4);
var otherNumbers = x.substring(0,x.length-4);
if(otherNumbers != '')
lastThree = ',' + lastThree;
var res = otherNumbers.replace(regex, ",") + lastThree;
alert(res);
</script>
</html>
In above code, I am using
var stringToGoIntoTheRegex=2;
var regex = new RegExp("\B(?=(\d{"+ stringToGoIntoTheRegex+"})+(?!\d))" , "g");
But this does not seem to work.
Output should be :1,23,45,65,24,578
Every help would be precious.