Skip to main content
Known Participant
March 27, 2017
Answered

Accepts numbers with 2 decimal places, as well as add "%" sign if needed

  • March 27, 2017
  • 1 reply
  • 1096 views

is it possible to do this in Acrobat using javascript?

Thanks,

Reymund

This topic has been closed for replies.
Correct answer try67

it doesn't allow me to insert '%' sign after i input a number.

if I input '%' first, i can't insert anything else too


Where are you trying to insert the percentage symbol? I thought you wanted it before the number... If you want it after then use this code instead:

event.rc = /^\d*\.?\d{0,2}%?$/.test(AFMergeChange(event));

1 reply

Inspiring
March 27, 2017

It's possible, but if you'd like help with a script you need to describe in more detail how you'd like it to behave. Some example entries would be helpful.

iammundAuthor
Known Participant
March 27, 2017

A user needs to enter a value (number) on certain textbox and it needs to have at least 2 decimal places. Also, that value can either have a '%' sign or not, depending if '%' sign is necessary.

I can user the Number format and make it two decimal places, however, it won't allow the user to input '%' sign since it only accepts integers.

The first code I used is this:

//Custom Format Script:

if (event.value !=="" && !isNaN(event.value)){

event.value = util.printf("%.2f%",event.value);

}else{

event.value = "";

}

it automatically adds a '%' sign whenever a user inputs a value. But my Client ask me if the '%' sign can be added only if necessary.

I hope it helps.

Thanks

Legend
March 27, 2017

When is it necessary (and not necessary)?