Skip to main content
August 26, 2017
Answered

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

  • August 26, 2017
  • 1 reply
  • 1384 views

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.

This topic has been closed for replies.
Correct answer try67

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);

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 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);

August 26, 2017

Thank you very much! You made my day.