Skip to main content
jctremblay
Community Expert
Community Expert
October 19, 2018
Question

Doing Regex F/C in Calculation

  • October 19, 2018
  • 2 replies
  • 706 views

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 -

ThisTo This
999999
99999-999
9999999-999
999999999-999
99999999-999-999


Possible... I can get some help on this. Thanks!

This topic has been closed for replies.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
October 19, 2018

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.

jctremblay
Community Expert
Community Expert
October 19, 2018

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?

Inspiring
October 19, 2018

It would be best to use a Validate script for that.

Inspiring
October 19, 2018

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;