Regex for Numbers which automatically add comma and decimal

Community Alums
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 01:33 AM
Hello,
I have a custom string field on record producer, which should allow only integers with decimals and add commas I have have added below script in catalog script but it's not allowing decimals and user is not allowed to enter only 0 value.
var result = formatNumber(newValue);
if(result == false){
alert('Only numeric values allowed');
g_form.setValue('u_opex_cost_yearly_in_usd', '');
return;
}
if(result != newValue){
g_form.setValue('u_opex_cost_yearly_in_usd', formatNumber(newValue));
}
}
function formatNumber(number){
var reg = /^[\d,]+$/;
if(!number.match(reg))
return false;
else
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Regards,
Prudhvi
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 09:44 PM
@Community Alums
try to debug line by line where it's failing
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2025 12:42 AM
@Community Alums
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader