- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2023 10:52 PM
Hello,
the below is my requirement.
for one of our clients there is a concern related to one variable.
cost variable for which we are validating its a numeric or not.
they want cost= 20,000.
not cost = 20000.
How to validate below scenario.
i have written below onchange script for cost to check whether it is numeric or not.
unction onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var decimalRegex = /^\d*(\.\d{1,2})?$/;
g_form.hideFieldMsg('cost', true);
if (!decimalRegex.test(g_form.getValue('cost'))) {
g_form.showFieldMsg('cost', 'Cost must be a numeric or 2 places decimal value.', 'error');
}
How to check the comma separated values in the script ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 03:49 AM
Hi @Are Kaveri,
It sounded like you only wanted validation of the entered format. Not that it changes it automatically...
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// remove any commas from earlier formatting
var value = newValue.replace(/,/g, '');
// try to convert to an integer
var parsed = parseInt(value);
// check if the integer conversion worked and matches the expected value
if (!isNaN(parsed) && parsed == value) {
// update the value
g_form.setValue('cost', new Intl.NumberFormat('en-US').format(value));
}
}
This should work
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:26 AM - edited 10-02-2023 12:27 AM
Hi @Are Kaveri
You can use this regex for your validation.
/^\d{1,3}(,\d{3})*(\.\d+)?$/g
I would recommend to use the OOTB Regex validation, instead of writing your own client script.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 03:25 AM
@nowgpt1 @Peter Bodelier i have tried both the regex but none of them were working . It was showing error message if i give more than 4 digits.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 03:27 AM
That is what you where asking for right?
20000 not allowed
20,000 allowed
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 03:29 AM
@Peter Bodelier i am entering 2000 but it should automatically take comma after 3 digits right. That is not happening it was throwing the error message.