Acrobat script which recognizes how to differentiate a gender from an alphanumeric number

Community Beginner ,
May 15, 2022 May 15, 2022

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:

  • First three letters of last name First letter of first name;
  • Digits represent YY MM DD and 2 administrative numbers.
  • Female see month added of 50, so;
  • January = 51 to December = 62
  • Examples: John Doe born January 20th, 1988 would be DOEJ 8801 2013
  • Sarah Andrews born October 13th, 1990 would be ANDS 9061 1312

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:

var ID = this.getField("ID").valueAsString;'
if (ID.length!=12) event.value = "";
else {
var dobString = ID.substr(4,6);
var dobObj = util.scand("yymmdd", dobString);
event.value = util.printd("yyyy/mm/dd", dobObj);
}

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. 

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

95

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

correct answers 1 Correct answer

Community Beginner , May 16, 2022 May 16, 2022

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!

Likes

Translate

Translate
Adobe Community Professional ,
May 16, 2022 May 16, 2022

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.

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 Beginner ,
May 16, 2022 May 16, 2022

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:

  • Kevin Li -> XLIK 9999 9999

2. I think the solution would be -> util.printd("yy/mm/dd"). 

  • if someday someone know where is the indicator, i could try to script a code similar as one you made in an older post using "var.genderMarker".

 

Thanks.

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
Adobe Community Professional ,
May 16, 2022 May 16, 2022

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.

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 Beginner ,
May 16, 2022 May 16, 2022

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:

  • John Doe 1969 12 31 --> DOEJ 6912 3102
  • "            " 1970 01 01 --> DOEJ 7001 0112
  • "            " 2070 01 01 --> DOEJ 7001 0122

is this make sense ?

thanks again.

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
Adobe Community Professional ,
May 16, 2022 May 16, 2022

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?

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 Beginner ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Exactly.. my bad....!

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
Enthusiast ,
May 16, 2022 May 16, 2022

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="";
}

 

@+

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 Beginner ,
May 16, 2022 May 16, 2022

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!

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
Enthusiast ,
May 16, 2022 May 16, 2022

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="";
}

@+

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 Beginner ,
May 17, 2022 May 17, 2022

Copy link to clipboard

Copied

LATEST

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 🙂

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