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

Adobe Pro DC: Extracting digits from a field and adding punctuation

Guest
Aug 26, 2017 Aug 26, 2017

Hi,

I have a field called «ID.number» where the users fill inn a number. The number contains a birth date and five other digits and will always be in this format: "DDMMYY00000".

I want to extract the birth date from the field and add it to a new field called «birth.date.» The output should be: dd.mm.yy (or dd.mm.yyyy)

Can anyone help me with a script so I can extract the numbers and add punctuation marks between the digits? (I do not usually work with javascript)

I have managed to get the first six digits in the new field, but I do not know how to add punctuation marks. Right now I only get «DDMMYY» instead of «DD.MM.YY».

This is my current script:

  1. this.getField("birth.date").value = event.value.substr(0,1)
  2. this.getField("birth.date").value = event.value.substr(0,2)
  3. this.getField("birth.date").value = event.value.substr(0,3)
  4. this.getField("birth.date").value = event.value.substr(0,4)
  5. this.getField("birth.date").value = event.value.substr(0,5)
  6. this.getField("birth.date").value = event.value.substr(0,6)

Thank you for your help.

TOPICS
Acrobat SDK and JavaScript , Windows
1.5K
Translate
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

correct answers 1 Correct answer

Community Expert , Aug 26, 2017 Aug 26, 2017

Use this code as the custom calculation script of "birth.date":

var id = this.getField("ID.number").valueAsString;

if (id.length<6) event.value = "";

else event.value = id.substring(0,2) + "." + id.substring(2,4) + "." + id.substring(4,6);

Translate
Community Expert ,
Aug 26, 2017 Aug 26, 2017

Use this code as the custom calculation script of "birth.date":

var id = this.getField("ID.number").valueAsString;

if (id.length<6) event.value = "";

else event.value = id.substring(0,2) + "." + id.substring(2,4) + "." + id.substring(4,6);

Translate
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
Guest
Aug 26, 2017 Aug 26, 2017

Thank you very much! You made my day.

Translate
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
Guest
Aug 28, 2017 Aug 28, 2017

I have the same scripts/Field names as mentioned over.

1. Is it possible to let the user overwrite the birth date Field?

2. In my case, the users sometimes type in a different ID-type. If a number is over 311299 (a date over 31.12) I do not want it to autopopulate the birth date Field. Do you know about an "exception" script I can use for this purpose? The users must then be able to fill out the birth date Field manually.

Thank you

Translate
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 ,
Aug 28, 2017 Aug 28, 2017

1. Yes, but it will require adjusting the code and moving it to be a custom validation script of the id field.

2. That's possible as well, yes.

Translate
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
Guest
Aug 28, 2017 Aug 28, 2017

Thank you for Your reply.

I am trying to sove nr 1: Let the users be able to overwrite the birth date Field.

Can you please help me with adjusting the script? I have moved it over to the id Field as you recommended. I can now overwrite the birth date Field, but I am not sure how i adjust the code to make the punctuation appear. I have only changed the recerence ("ID.Number") to ("birth.date)". (I am not used to scripts)

Translate
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 ,
Aug 28, 2017 Aug 28, 2017

If the user clears the value of "ID.Number", should it also clear the value of "birth.date"?

Translate
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
Guest
Aug 28, 2017 Aug 28, 2017

I Guess yes, since the birth date is a "Product" of the ID, it should be removed if the ID is cleared.

Translate
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 ,
Aug 28, 2017 Aug 28, 2017

Try this:

var id = event.value;

if (id.length<6) this.getField("birth.date").value = "";

else this.getField("birth.date").value = id.substring(0,2) + "." + id.substring(2,4) + "." + id.substring(4,6);

Translate
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
Guest
Aug 28, 2017 Aug 28, 2017

Yes, that worked! Thank you so much!!

Translate
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 ,
Aug 28, 2017 Aug 28, 2017

Use this code to implement your second request, too:

var id = event.value;

var birthDateField = this.getField("birth.date");

birthDateField.value = "";

if (id.length>=6) {

    var dob = util.scand("ddmmyy", event.value);

    if (dob!=null && dob.getFullYear()>=2000) {

        birthDateField.value = util.printd("dd.mm.yy", dob);

    }

}

Translate
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
Guest
Aug 28, 2017 Aug 28, 2017
LATEST

Again, thank you so much! This is exactly how I wanted it to work.

Translate
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