• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Doing Regex F/C in Calculation

Community Expert ,
Oct 19, 2018 Oct 19, 2018

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 -

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


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

TOPICS
Acrobat SDK and JavaScript

Views

162

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2018 Oct 19, 2018

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;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2018 Oct 19, 2018

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2018 Oct 19, 2018

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2018 Oct 19, 2018

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines