Acrobat 6: Field validation

I need to validate a field onBlur with JScript:

- should be numeric (1 to 9999999999)
- spaces should be trimmed

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:
Do you want the user to enter spaces? The most straight forward approach would be to only allow numeric information to be entered. You can do this by opening the properties dialog for your field. Then select the "Format" tab and select the format category "Number". Specify how many decimal places, then select the "Validation" tab and specify the limites (1 to 9999999999).

If this is not sufficient, I can give you more information about how to do this with JavaScript.
go4javaAuthor Commented:
Is more a regular expression: The first char should be 1 to 9 (not 0!) and the follwoing 9 chars should be 0 to 9.
Karl Heinz KremerCommented:
This took a little longer than I exptected: I run into a bug in Acrobat and had to find a workaround first. It looks like whenever I'm using AFMergeChange() in a custom keystroke script, Acrobat "forgets" the script.

You need to use a custom keystroke script to do what you want to do. Such a script gets run for every keystroke that a field receives. Depending on the return value of the event, the keystroke is then either accepted, or rejected. In your case, you would reject all non-digit characters, and the zero for the first position, and also all characters after the string length exceeds the  number of valid digits.

Open your form and select the Advanced>JavaScript>Document JavaScripts... menu item. Create a new script that you name "validateField" and click on the "Add" button. In the edit field, add the following script:

function validateField(ev)
    var newValue = AFMergeChange(ev);
    var re = /^[1-9][0-9]*$/g;
    var res = false;

    if (newValue.match(re))
        if (newValue.length <= 10)
            res = true;

    return res;
// end of script

Then open the properties dialog for your form field and select the "Format" tab. Click on the "Edit" button for the "Custom Keystroke Script". Then use the following command as your custom keystroke script:

event.rc = validateField(event);
// end of script

This will assign either true or false to the rc property of the event object. This either accepts or rejects the keystroke.

The actual validation routine uses a regular expression to first make sure that you have a number that starts with 1 to 9, and then iin a second step makes sure that the string is 10 characters or shorter.


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
go4javaAuthor Commented:
Thank you,
I found the workaround:

1. onBlur

- conversion if field content to String! (--> 01 will not be parsed to 1)
var sNodeString = sNode.valueAsString;

2. Test field content with regular expression

var regExpr =  /^[1-9][0-9]{0,9}$/;
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.