How to use proper regex in textbox to form formatted text

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

I have a textbox for inputting some amount. It's a number field, and I want to make it formatted properly. For example, suppose I want to input 100000. So when user type 1000 it will be changed to 1,000 and upon typing of an additional 0 it would be 10,000, for one more 0 it will 1,00,000. I tried with some regex available over internet, but none of them works for an input type. What's the probable way to achieve that?

Thabnks!

Hi @Svwvh Rvndvll​

Please use this code in onTextChange method of your TextBox:-

function setValueWithComma()

{

var value = YourFormName.TextBoxName.text;

YourFormName.TextBoxName.text= putComma(value);

}

function putComma(num) {

num = num.toString().replace(/,/g, '');

x = num.split('.');

x1 = x[0];

x2 = x.length > 1 ? '.' + x[1] : '';

var rgx = /(\d+)(\d{3})/;

while (rgx.test(x1))

x1 = x1.replace(rgx, '$1' + ',' + '$2');

return x1 + x2;

}