Solved

Acrobat dropping leading zeroes when I have to use a regex script in a form field.

Posted on 2008-10-29
12
929 Views
Last Modified: 2012-05-05
Good (insert timezone specific and culturally sensitive greeting)!
I am using the attached code that I think khkremer provided originally.
I use it specifically to remove dashes from social security numbers.
Well I found out today that once this script runs it drops leading zeroes.
So, if a social is 012-34-5678 this script will make it 12345678.

I think I have to turn it back into "not a string" cause I thought it had to be turned into a string for the regex to work properly..
If anyone can help, that would be greatly appreciated.

I am running this as a custom calculate script, if that is needed to be known.

Thanks again for your time and help.
var str = event.target.value + "";

str = str.replace(/[^0-9]+/g, "");

event.value = str;

 

this.getField("OSSN").value = event.value;

Open in new window

0
Comment
Question by:JohnnyOffTheSpot
  • 6
  • 6
12 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22837300
It seems to work for me. I just tried the script with Acrobat 9 Pro (on a Mac however, but that should not make a difference). When I enter "012-34-5678" I end up with "012345678"

Where do you see the dropped zero? Right on the UI, or is that something that shows up later?
0
 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22837531
oh man, I am really frustrated now.  I made a new blank pdf and created form fields and added the script.  worked fine.  I then copied the actual fields from my documents to a new blank pdf and they work fine too!

I can't post my file because of legal, but it doesn't work.  

I have 2 document level scripts for placing specifically formatted dates into 2 fields and the rest are acroforms.  No other script refers to either of those fields and their formatting is set to none, they also don't have any other scripts attached.
And for an added bonus the leading zeroes are only removed if this script applies to field that copies it's value to another field.
So if I just have this:
 var str = event.target.value + "";
 str = str.replace(/[^0-9]+/g, "");
 event.value = str;
It works fine!

Anyone have ANY idea what could possibly be happening?
Could someone point me in the direction of finding out how to use the debug from start.
when I run it it pauses on some scripts but not others that are the same, I'm missing something here.

thanks again for the help.

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22839584
Let me see if I understand: As soon as you add the following line, the leading zeros get removed?
this.getField("OSSN").value = event.value;

I actually had that in my script as well (I created a text field named OSSN).
0
 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22840242
Yeah like I said.  If I copy my 2 fields from the pdf document to a brand new blank pdf it works without removing leading zeroes, just like you said above.
But any script in my main document that contains any regex AND copies the data to another field will remove leading zeroes.
It's crazy.
My main document is about 8 pages and roughly 500 form fields, it would seem unreasonable to have recreate it to fix this.

I think my question has turned from the original to how can I scan my document for script problems.  I will do some heavy searching for that now, but if you have any ideas they would be welcome.

Thanks for your input.


0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22840411
Would you be able to remove all content of your form (e.g. replace with blank pages) and then make the form available to me? You can replace the content of a form by using the "Document>Replace Pages" function, just select a document that has the same number of pages as your form (but blank).
If you don't want to upload the document to EE, you could also email it to me directly (my email address is on my profile page).
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22840433
Re: Debugger: Have you used the Advanced>Document Processing>Debug from Start option?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22864431
ok sorry for the long response time.
When trying to make you a file, that I could send.  I uncovered some other problems with scripts and several problems on my machine, related to java that could not be fixed with add/remove, re-load.  So, I did a complete reinstall of my machine with all the latest available stuff for xp pro. For fun I installed the acrobat 9 pro extended trial from adobe.com. (really nice with some, kinda of annoying, changes but anyway). And tada, everything works fine.  BUT (dun, dun, dahhhh!), if I go back and have to make an edit to my form field and enter just a new social, properly formatted for me (just numbers) and it starts with a zero.  It will still drop that leading zero.  
If I then add the zero and at least 1 character that is not 0-9, it works fine.

If the regex has nothing to do and the field data contains a leading zero, it gets dropped.
The same thing happens on another computer we have with acrobat 7 pro.
This is a big hindrance for me because we receive files that people have entered their socials without formatting and that leading gets truncated.

I would be curious to see if you have the same results on the mac, try just typing in 012345678 and let that regex do it's magic.

I have tried the following permutations with and without the copying to the OSSN field, with no better results.

Thanks again.
I would like to hear from anyone with xp and what they get if they run this script with just 01234 entered, does it drop the 0?

str = str.replace(/[^0-9]/g, "");

str = str.replace(/[^0-9]+/, "");

str = str.replace(/[^0-9]/, "");

str = str.replace(/[^1,2,3,4,5,6,7,8,9,0]/, "");

Open in new window

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 22866457
Your "If I then add the zero and at least 1 character that is not 0-9, it works fine." implies that reason for the change is that a variable is either interpreted as a string (which would keep the leading zero) or as a number (which would drop it). Once you add a non-digit, JavaScript will interpret the variable as a string.

I'm not sure what you are asking me to do: I type "012345678" into what form, running what script?
0
 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22866545
here, let me attach a sample.

in the first field that runs the regex that I originally posted as a code snippet, type any combination numbers and letters but make the first character a zero.
The when you click away it will strip everything but the numbers, leaving the leading 0.
Now click in again and type a new number starting with a 0, say, 012345.
The regex that is only supposed to remove everything but 0-9 will actually remove the 0.

My understanding of adding:
var str = event.target.value + "";
would have stopped this the digits from being interpreted as numbers.



Untitled.pdf
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 22866681
Change the event.target.value to just event.value - I don't know why I added the target here. It's not necessary (I think) and changes the behavior of the variable.
0
 
LVL 2

Author Comment

by:JohnnyOffTheSpot
ID: 22866738
that did it and it seems to fix everything.

KHKREMER, an acrobat god among mere mortals!
Thanks for you help.
0
 
LVL 2

Author Closing Comment

by:JohnnyOffTheSpot
ID: 31511452
thank you again, you are a huge help and I really appreciate your time and effort.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now