Variable for decimal and commas combination
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:19 PM
Hello Everyone,
I need to have variable on my record producer form which is will only allow to enter the numbers values in he decimal and comma format.
we are able to achieve this but the thing is once value is entered and then again try to enter few more numbers it is not taking the format.
for example: if i enter amount as 198.99,000 then in same if i enter extra numbers 198.99,000899090like this it is not taking commas.
Can anyone help me on this. we tried to achieve this on change client script.
Thanks you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:28 PM
Hi,
Are you using some kind of regular expression to validate the field?
If so, an expression like this one will allow only to enter numbers, commas and dots, and you can use it to test if the entered value match, and if not give an error message and clear the field.
var regex = /[\d,.]/;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:57 PM
we are using like var reg = /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:(\.|,)\d+)?$/;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2022 02:27 PM
That seems like a very complicated regex.
If you want to ensure numbers, followed by an optional comma and some more digits, you could simplify it, something like this.
var regex = /^-?[\d]+([,][\d]{1,4})?$/;
Can you share your client script for also?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2022 10:30 PM
HI you can do like this. Try in bg script
var num = 1234567.89;
var commas = num.toLocaleString();
var commas = num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); // will add comma after 3 digits
gs.info(commas);
https://code-boxx.com/add-comma-to-numbers-javascript/
Harish