Copy link to clipboard
Copied
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:
Thank you for your help.
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);
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Thank you very much! You made my day.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
If the user clears the value of "ID.Number", should it also clear the value of "birth.date"?
Copy link to clipboard
Copied
I Guess yes, since the birth date is a "Product" of the ID, it should be removed if the ID is cleared.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
Yes, that worked! Thank you so much!!
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Again, thank you so much! This is exactly how I wanted it to work.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more