Copy link to clipboard
Copied
Hi, I'm verry new to script, and it's the first time I'm trying to build a form on Acrobat Pro with some required information.
I use an alphanumeric id which is made of 4 letters and 8 digits, built like:
I'm unsure how to deal with the yy of Y2K, but I could deal with it after (I guess it's in the 2 last digits, but cannot see any difference in numbers of 19' and 20' subject ID number..)
I was able to extract date of birth (dob) from male subject with a script inspired from try67 older post's:
I'd like to be able to extract female (dob), even if the month value is 50 more... It would also be awesome to be able to use the 0-1(M)/5-6(F) value of the ID's 6th digit to fill a dropdown box with Male or Female choice.
I've red a lot of post, watch tutos, but could'nt find any answer.. may I please ask someone a little help 🙂
Thanks,
David.
well its impressive (for someone who've never deal with coding) to see how you can handle it!
Wow! Great job! Works perfectly (w/o Y2K trouble) but i can i can handle it after..
Thanks a lot!
Copy link to clipboard
Copied
This is a duplicate of your other post, but with more details, so let's continue here. In the future, do not post the same question multiple times, please.
There are multiple problems with how you generate these ID's:
1. What if the surname of the person is only two letters, like "Li"? Your code will not allow them to have an ID.
2. Representing a DOB year with only 2 digits exposes you to the Y2K-bug, meaning you can't differentiate between people born in 1920 and 2020, for example.
I recommend you handle these two issues first, then move on to the code.
Copy link to clipboard
Copied
Hi,
sorry for duplicata. I've asked a moderator to delete the first one.
ok let's see:
1. If the person has a 2 letter surname, the number on the ID will start with an X:
2. I think the solution would be -> util.printd("yy/mm/dd").
Thanks.
Copy link to clipboard
Copied
1. I hope you're not using this ID to reverse engineer the person's name later on, then...
2. That won't solve anything. You still can't know if the birth year is 1920 or 2020, based solely on the ID.
Copy link to clipboard
Copied
1. (if i understand correctly (not english as first language)): should not be use for that.
2. i think i've found (called my grandma for that): since the number was created in 1970, everyone born before 1970, the 11th digit of the card is a 0, after it's a 1, and by 2070 will be a 2:
is this make sense ?
thanks again.
Copy link to clipboard
Copied
Yes, that would make sense... Not an ideal solution, but it should work for the time being.
But you gave an example of "October 13th, 1990 would be ANDS 9061 1312". Shoudn't that be November?
Copy link to clipboard
Copied
Exactly.. my bad....!
Copy link to clipboard
Copied
Hi,
Are the first letters typed manually?
If so you can use a custom keystroke script which allows to type 3 or 4 letters:
if(!event.willCommit) {
var aTester=event.value.split("");
aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
var testeChaine=aTester.join("");
var modeleRegEx=/^((\w{0,3}|\w{0,4})\d{0,2}(((0|5)[1-9]?|(1|6)[0-2]?)(((0)[1-9]?|(1|2)[0-9]?|(3)[0-1]?)\d{0,2})?)?)?$/;
event.rc=modeleRegEx.test(testeChaine);
} else {
var modeleRegEx1=/^\w{3}\d{8}$/;
if (modeleRegEx1.test(event.value)) nbChar=3;
else nbChar=4;
var modeleRegEx2=/^\w{4}\d{8}$/;
event.rc=event.value=="" || modeleRegEx1.test(event.value) || modeleRegEx2.test(event.value);
}
Then a calculation script for the dob field:
var ID=this.getField("ID").valueAsString;
if (nbChar==3) var idRegEx=/^\w{3}\d{8}$/;
else var idRegEx=/^\w{4}\d{8}$/;
if (idRegEx.test(ID)) {
var theYear=ID.substr(nbChar,2);
var theMonth=ID.substr((nbChar+2),2);
if (Number(theMonth)>12) {
theMonth=Number(theMonth)-50;
if (theMonth<10) var theMonth="0"+theMonth;
this.getField("gender").value="Female";
} else {
this.getField("gender").value="Male";
}
var theDay=ID.substr((nbChar+4),2);
var dobObj=util.scand("yymmdd", theYear+theMonth+theDay);
event.value=util.printd("yyyy/mm/dd", dobObj)
} else {
event.value="";
}
@+
Copy link to clipboard
Copied
well its impressive (for someone who've never deal with coding) to see how you can handle it!
Wow! Great job! Works perfectly (w/o Y2K trouble) but i can i can handle it after..
Thanks a lot!
Copy link to clipboard
Copied
...and here is a new version to manage the date before 1970 in accordance with the 11th digit (if it's 0, the date will begin by 19..):
var ID=this.getField("ID").valueAsString;
if (nbChar==3) var idRegEx=/^\w{3}\d{8}$/;
else var idRegEx=/^\w{4}\d{8}$/;
if (idRegEx.test(ID)) {
var theYear=ID.substr(nbChar,2);
var theMonth=ID.substr(nbChar+2,2);
if (Number(theMonth)>12) {
theMonth=Number(theMonth)-50;
if (theMonth<10) var theMonth="0"+theMonth;
this.getField("gender").value="Female";
} else {
this.getField("gender").value="Male";
}
var theDay=ID.substr(nbChar+4,2);
var dobObj=util.scand("yymmdd", theYear+theMonth+theDay);
theDate=util.printd("yyyy/mm/dd", dobObj);
if (Number(theDate.substr(2,2))<70 && Number(this.getField("ID").valueAsString.substr(nbChar+6,1))==0) event.value="19"+theDate.substr(2);
else event.value=theDate;
} else {
event.value="";
}
@+
Copy link to clipboard
Copied
Wow wow wow! You're the man!
Also inspires me a lot for my next formulas!
Thanks A LOT again, everyone, and have a great day 🙂