Copy link to clipboard
Copied
I need to format a series of numbers with - between each 3 digits.
Easy to do with a simple REGEX, my difficulty is to know how and where to put a javascript to make the content of a field to display with the -
This | To This |
---|---|
999 | 999 |
9999 | 9-999 |
99999 | 99-999 |
999999 | 999-999 |
9999999 | 9-999-999 |
Possible... I can get some help on this. Thanks!
Copy link to clipboard
Copied
One could also use the "util.printx" method. No matter which approach one uses, determining the length or value range of the strings will also need to be done.
What ever script you use the "Custom Format" on the "Format" tab. This will only affect the field display and not the actual field value;
Copy link to clipboard
Copied
Anything that does not actually change the contents of a field, and only affects the formatting would be done in a formatting script. If you want to also constrain what the user can enter, you would have to add a validation script to make sure that only valid characters matching the correct pattern can be entered.
You would get the current value as event.value, which you would modify and then pass back the modified value again as event.value in your custom formatting script.
Copy link to clipboard
Copied
After many trial and error I get it... in custom format script using this:
event.value = event.value.replace(/(\d)(?=(\d\d\d)+\b)/g,"$1-");
If I want to actually replace the content, not just the display, i'm correct to say I can use this in Custom Keystroke Script Format instead?
Copy link to clipboard
Copied
It would be best to use a Validate script for that.