
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 01:21 PM
I have a service catalog item that has a field used to enter a number, which is then mapped to a Price field on the task form. I've seen a few posts on enforcing characters and requiring users to enter a dollar amount in the correct format, which is fine, but what I'm being asked to do is the following:
Validate that no letters or characters not normally associated with US currency are allowed (0-9 $ , .)
Format the number as it is typed to automatically insert commas at the correct intervals (eg. 1,000 10,000 100,000 etc.)
Automatic insertion of the comma is to help prevent user error when they type something like 25000 quickly but meant to type 250000. Trailing zeros can make it difficult to spot errors, apparently
Not sure if there is really a way to do this. Would be nice to have an Integer type field for the service catalog.
Solved! Go to Solution.
- 7,014 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 10:24 PM
Hi Marcel,
You can try below script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var result = formatNumber(newValue);
if(result == false){
alert('Only numeric values allowed');
return;
}
// To avoid recusrion
if(result != newValue){
// Change u_field_name to the field on which this onChange script is applied
g_form.setValue('u_field_name', formatNumber(newValue));
}
}
function formatNumber(x) {
// Regular expression allowing only numeric values
var reg = /^[\d,]+$/;
if(!x.match(reg))
return false;
else
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); // Insert commas at correct position
}
Let me know if this works fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2021 11:06 AM
Hi Marcel
Could you support me in sharing your regex? is that I have searched everywhere how to allow at least two decimal numbers and a dollar sign.
I hope I can count on your help.
Greetings.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2017 10:44 PM
Hi Mohammed,
I need to add ,00 automatically at the end of numbers. For example 250.343.343,00
I tried to combine script below with the code you shared, but i couldnt accomplish. Could you help, please?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var curval = newValue.split(",")[1];
if(curval == undefined || curval.length != 2)
g_form.setValue('myfield',parseFloat(newValue).toFixed(2));
// Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 05:41 AM
Hi Zee,
I have a variable cost, when I enter value in that it should take in commas,
Example: when I enter 1000, it should display 1,000 while I am entering.
Can you please suggest me on that.
Thanks,
Uzma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2019 06:07 AM
I got but can you help me with one requirement. If we have different forms of currency like USD, EUR etc based on that commas should come. Can you help me with script?
Thanks,
Uzma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2022 02:59 AM
Hello bro,
Your script is very helpful. But can you please help me on this requirement?
User needs to show comma on the numeric field same as above BUT also
- Require support 2 decimals.
- The value could not be exceed 999,999,999.99