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

Setting number format to a text field

ceci_d
Registered: Jul 9 2007
Posts: 4

Hello, does anybody know how can I set a text field's format to Number with JavaScript? I need to do that dynamically, so I can't use the designer.

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Try the following as a custom format script:

this.getField(event.target.name).setAction("Format", 'AFNumber_Format(2, 0, 0, 0, "$", false)');


The Acrobat proviced forms function call:

AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)

nDec = number of decimals
sepStyle = separator style 0 = 1,234.56 / 1 = 1234.56 / 2 = 1.234,56 / 3 = 1234,56 /
negStyle = 0 black minus / 1 red minus / 2 parens black / 3 parens red /
currStyle = reserved
strCurrency = string of currency to display
bCurrencyPrepend = true = pre pend / false = post pend

George Kaiser

ceci_d
Registered: Jul 9 2007
Posts: 4
10x !
that worked
StevenD
Registered: Oct 6 2006
Posts: 368
Two questions:

1. Where do I find documentation for such things as AFNumber_Format?

2. Is there a way using JavaScript to make it so a field can only except numerics? For example a field where a user is supposed to enter a five digit item number as in 30589. I could set the format of the field to be a number but I don't want my number to be displayed as 30,589.

StevenD

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
It should be noted this technique works with Adobe Acrobat products, as this function is part of the JS functions distributed by Adobe with Acrobat/Reader.

There was a brief explanation in Version 5's JavaScript Reference.

You can use the "Format" tab to select the "Number" format and then select the appropriate formats for separator and decimal and negative display.

Or you can use the "Custom" format and use JavaScript's RegExp to write custom keystroke and format scripts.

George Kaiser

StevenD
Registered: Oct 6 2006
Posts: 368
Thanks. I just need to find a JS Reference for Acrobat 5. Hope someone here in the building has one.

I keep forgetting about RegExp. Thanks for the reminder and the response.

Steven

StevenD

StevenD
Registered: Oct 6 2006
Posts: 368
Is there a sample of a regular expression in a custom format that I could look at. I'm not asking for a solution to what I am working on. I just want to see what one looks like in an Acrobat context so hopefully it can help me figure how to use regular expressions.

StevenD

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Here 2 links to some RegExp coding:

A custom phone number:

http://forum.planetpdf.com/wb/default.asp?action=9&read=54883&fid=34#150230Processing 10 and 13 digit ISBN codes:

http://forum.planetpdf.com/wb/default.asp?action=9&read=51537&fid=5#140994

George Kaiser

StevenD
Registered: Oct 6 2006
Posts: 368
Thanks for some great links and material. This should help.

StevenD

Alle Mogaga
Registered: Mar 4 2010
Posts: 1
Is it possible if the value 0 (zero) is displayed "-" (hypen or minus sign)?
For example:
"1234567.00" --> "1,234,567.00"
"0.00" --> "-"Alle