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

Validating numbers in a text field

nmjfaulkner
Registered: May 24 2010
Posts: 29

Here are my needs:

1. Accept only 6 numeric digits
2. Check that all 6 digits are numbers (0-9)
3. Do not allow any character other than 0 through 9
4. Null out the entered value if it is not a 6 digit number
5. Pop an alert
6. Set focus back to the field

I cannot seem to make the Numeric Field allow only 6 digits, and cannot accept the case where the user enters just a "1" and it backfills 0000001, etc. Using a textfield having trouble with a function call.

I am using Acrobat 9.3.3 for all users, and using LiveCycle Desginer ES2 9. Most of the examples I find on the net seem touse depricated functions, so at a loss how to do this. This is NOT an HTML page but a PDF form.

Ideally it would be a function I call at an EXIT event from the field and do the test. The Null and alert I can handle fine. Just can't seem to get the function right.

ZNum is the textfield name.

Any help is appreciated.

Thanks

My Product Information:
LiveCycle Designer, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You will need a regular expression to do the validation. This one, for example:
var patt1=/^\d{6}$/i;
You can then use the test() method on a string to make sure if conforms to the expression (which it will only do if it is made out of six digits, and nothing more, or less). You do that like so:
var str1 = "123456";patt1.test(str1); // will return true var str2 = "1234567";patt1.test(str2); // will return false var str3 = "a123456";patt1.test(str3); // will return false var str4 = " 123456";patt1.test(str4); // will return false

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

nmjfaulkner
Registered: May 24 2010
Posts: 29
try67 -

Thanks, but I a not seeing a test() method as a valid piece of code.

Searching through the "LiveCycle ES2 Designer Scripting Reference" pdf put out by Adobe I do not find "test()" anywhere.

I have tried creating a script object on the page called ZNumCheck, and wrote a function in it as such:

function IsValid(oField){

var patt1 = /^\d{6}$/i;

if ((patt1.test(oField) == false)
{
app.alert("Number invalid");
oField.rawValue = null;
xfa.host.setFocus(oField);
}

}

I then use the EXIT event on the field to call

ZNumCheck.IsValid(this)


This doe snot execute. I can place other code in the function and see that I am properly passing the value into it, just not this test method. I have no knowledge at all of testing strings in javascript, and how to capture their returns!

Thanks,