These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding "Zeros" in front of a number ...

hedrich
Registered: Nov 26 2008
Posts: 28
Answered

I have some problems concerning one text field in my acrobat form.

One text field of my form contains a "matrikel"-number of the students (for example: 123456). These number must be changed to the format: "000000123456".

Is there a script for adding "Zeros" in front of the imported number, until the number has 12 digits (with leading "Zeros") ???

Kind Regards
Holger

My Product Information:
Acrobat Pro 9.0, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Something like this?

a="1234";
for (i=12-a.length; i>0; i--) a="0"+a;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hedrich
Registered: Nov 26 2008
Posts: 28
Hi try67,

thanks for your prompt answer.

But where the script must be placed ?

Is this script for variable combinations or only for "1234"?

Kind Regards
Holger
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Where the script is to be placed depends on you... I don't know where you want this new value to appear. And this script will work for a string of any length. You can paste it in the Java Console of Acrobat and change the value of "a" to see for yourself.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hedrich
Registered: Nov 26 2008
Posts: 28
Hi try67,

the original number (without the zeros) will be imported from a tab.txt - database into a textfield of my acrobat form. In this textfield the number should be completed with the zeros.

Kind Regards
Holger
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
You should probably use a custom Validate script for each such field, which could look like:

(function() { // Set the maximum length for the zero-padded stringvar max_len = 12; // Get this field's valuevar val = event.value; // Pad value with zeroes if the string is less than the maximum lengthwhile (val.length < max_len) {val = "0" + val;} // Set this field valueevent.value = val; })();

George
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I would use a custom format script or calculation script using the "util.printf()" method:

event.value = util.printf("%,3012d", event.value);

George Kaiser