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

Allow numbers only AND add static text to final value?

esmith818
Registered: Aug 4 2010
Posts: 7
Answered

*SOLVED* (see 2nd post)

I've spent the last 24 hours scouring the web for a solution to this problem without luck. I am trying to create a field on an Acrobat form that only allows numbers (and decimal) for input, and then formats the result with an added "WAS $" in front. I do not want the user to enter the dollar sign or the WAS text to enforce all forms created by various users to include the same wording.

Thanks to this site I was able to figure out that by adding
event.value = "WAS " + util.printf("$%,0.2f", event.value);
as a Custom Format Script, I could handle the addition of the "WAS $" static copy and format a valid value in a $#.## format.

Separately, I determined that by adding

var re = /[0-9.]/; 
if (re.test(event.change)) { 
  event.rc = true;
} else event.rc = false;

as a Custom Keystroke Script I could force number and decimal entries only.

What doesn't seem to work is combining these two scripts to do both. If I use just the former code, an end user could attempt to enter alpha characters and/or symbols and get the result "WAS $nan". If I go with just the latter, I actually get nothing for a result? Can someone please steer me in the right direction to achieve the ultimate goal I need?

I am using Acrobat Pro 9.3.3 (not an option in forum dropdowns) on Mac OS X 10.6.3.

My Product Information:
Acrobat Pro 9.3.1, Macintosh
esmith818
Registered: Aug 4 2010
Posts: 7
Wouldn't you know that as soon as I posted this, I found my answer digging a little more on this site!

I located (http://www.acrobatusers.com/tutorials/2006/formatting_text_fields) which explained the "correct" way to allow only number and decimal keystrokes, which worked beautifully with the format script I was already using to add the "WAS $" copy.

Sorry for causing a stir first thing in the morning. But it did lead me to find a fantastic resource for Acrobat form editing. :)