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

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

LVL 2
JohnnyOffTheSpotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karl Heinz KremerCommented:
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
JohnnyOffTheSpotAuthor Commented:
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
Karl Heinz KremerCommented:
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

JohnnyOffTheSpotAuthor Commented:
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
Karl Heinz KremerCommented:
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
Karl Heinz KremerCommented:
Re: Debugger: Have you used the Advanced>Document Processing>Debug from Start option?
0
JohnnyOffTheSpotAuthor Commented:
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
Karl Heinz KremerCommented:
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
JohnnyOffTheSpotAuthor Commented:
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
Karl Heinz KremerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JohnnyOffTheSpotAuthor Commented:
that did it and it seems to fix everything.

KHKREMER, an acrobat god among mere mortals!
Thanks for you help.
0
JohnnyOffTheSpotAuthor Commented:
thank you again, you are a huge help and I really appreciate your time and effort.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Acrobat

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.