• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

Acrobat 6: Field validation

I need to validate a field onBlur with JScript:

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

Thanks.
0
go4java
Asked:
go4java
  • 2
  • 2
1 Solution
 
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.
0
 
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.
Examples:
123456
234
99999999
0
 
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.


0
 
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}$/;
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now