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

Forcing text only characters in a form field

RRomano158
Registered: Jul 11 2008
Posts: 5
Answered

I am using Adobe Acrobat 7.0 Pro. I have a form I made in Word, converted it to a PDF form and populated it with numerous form fields. The majority are plain text fields. I have learned, thru trial and error, how to add and edit those fields. One field in particular has to have the 2 digit characters of the States entered in (ie: FL, NY, CA, etc. or CAN for Canada). I found a solution on this website to allow that field to be forced to UpperCase and implemented it the custom keystroke window. However, I now need to force that form field to ONLY accept Alpha characters and NOT numerical characters. I could do this in the Special format area using the arbitrary mask unfortunately I can't use both formats: Special and Custom, at the same time.
Therefore I was wondering if there is another javascript custom keystoke or custom format that would limit that form field to alpha characters only and can also be used in conjunction with the UpperCase script already running?
I thought this would be a simple look up on the web, but after two days of searhing I haven't found any answers.

Thanks for any help.

My Product Information:
Acrobat Pro 7.0.9, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You can do what you want, but have you considered using a combo box field that contains the states/countries you want? If a combo box in not adequate, which characters, exactly, do you want to restrict the user to entering, and is there a maximum number of characters?

George
RRomano158
Registered: Jul 11 2008
Posts: 5
The form is actually six pages and contains several areas where the "State" field has to be entered. I really didn't want to have to enter all 52 + States in a combo box for each of the form fields that require it. I already have the character limit set at 3 in the options menu of each of the "State" form fields (just in case they have to enter a 3 digit alpha for an out of country state). I was hoping just for a quick script like the one I am using to force the text being entered to automatically capitalize. "event.change=event.change.toUpperCase();"

Thanks
Robin
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
What you want is a new custom keystroke script. Since it will be used by several fields, you should create a document level JavaScript (Advanced > JavaScript > Document JavaScripts), add a new one, and add the following code:function TRICHAR_ks() {

// Convert input to uppercase
event.change = event.change.toUpperCase();

// Get everything that the user has entered so far
var value = AFMergeChange(event);

// Do nothing if there are no characters
if(!value) return;

//If user attempts to enter an invalid sequence of characters, reject it
if(!AFExactMatch(/[A-Z]{0,3}/, value)) event.rc = false;
}


Now, as the custom keystroke script for each field that you want to do this for, use the following:

if (!event.willCommit) TRICHAR_ks();



George
RRomano158
Registered: Jul 11 2008
Posts: 5
Thank you very much.
That worked out perfect!!!

Robin