Skip to main content
Inspiring
May 15, 2022
Answered

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

  • May 15, 2022
  • 1 reply
  • 3615 views

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. 

This topic has been closed for replies.
Correct answer DavidL53

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

 

@+


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!

1 reply

try67
Community Expert
Community Expert
May 16, 2022

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.

DavidL53Author
Inspiring
May 16, 2022

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.

try67
Community Expert
Community Expert
May 16, 2022

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.