In the end it DID turn out to be a JavaScript issue. Last week someone pointed out that I was using replace instead of replace all which I missed not knowing much JaxaScript. This caused only the first comma to be replaced by a blank and second comma was left as a comma. When that string was put into tolocalestring there was a comma left and to locale string received at least one comma which made it fail. Once I used replaceall everything worked fine and I was able to type up to 12 digits with commas inserted correctly.