- 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 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 03:39 AM
Hi @Are Kaveri ,
Use below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var costValue = g_form.getValue('cost').replace(/,/g, '');
var decimalRegex = /^\d*(\.\d{1,2})?$/;
g_form.hideFieldMsg('cost', true);
if (!decimalRegex.test(costValue)) {
g_form.showFieldMsg('cost', 'Cost must be a numeric or 2 places decimal value.', 'error');
g_form.setValue('cost', oldValue);
}
}
Thanks,
Anand