Skip to main content
Participating Frequently
April 11, 2018
Answered

How to set a textfield that only accept number and comma (,) symbol ?

  • April 11, 2018
  • 1 reply
  • 10647 views

i use adobe acrobat XI pro and i want to set a text field in pdf form that only accept number and comma (,)

for example i can input 12 or 1,2

12 numeric or 1,2 numeric with comma (,)

the text field can accept number and the text field can accept numeric with comma (,) too

i've already used this code but it only accept number and reject the comma (,) symbol

"if(Math.floor(event.value) != event.value) { event.rc = false; app.alert("Enter integr values only"); }"

thanks for any help,

kurt

This topic has been closed for replies.
Correct answer try67

i'm beginner for this pdf form script sir

so can you please give me an example about using the "event.value" ? cause i never used that before

thank you for your help


I already did, in the code I provided above... Anyway, I think this is what you want to do:

if (event.value) {

    if (event.value=="0") {

        app.alert("Quantity cannot be 0!", 0);

        event.rc = false;

    } else {

        event.rc = /^\d+,?\d*$/.test(event.value) || /,$/.test(event.value);

        if (!event.rc) app.alert("Incorrect value!");

    }

}

1 reply

try67
Community Expert
Community Expert
April 11, 2018

You can use this code as the custom validation script of your field:

if (event.value) {

    event.rc = /^\d+,?\d*$/.test(event.value) || /,$/.test(event.value);

    if (!event.rc) app.alert("Incorrect value!");

}

Participating Frequently
April 11, 2018

hello mr try67
thanks for your answer

the answer actually correct, but when i try to run my pdf form, the other code of mine don't work after i add your code

here are the list of my code after adding yours :

var a = this.getField("date");

var b = this.getField("department");

var c = this.getField("q1");

var a2 = this.getField("d1");

var a3 = this.getField("dr1");

var a4 = this.getField("r1");

if (event.value) {event.rc = /^\d+,?\d*$/.test(event.value) || /,$/.test(event.value);

    if (!event.rc) {app.alert("Incorrect value!"); c.value='';}}

else if (c.value=='0'){app.alert("Quantity cannot 0!!", 0); c.value=''}

else if (c.value!='' && b.value=='-' && a.value==''){app.alert("You must fill in PR date and Department first!!", 0); c.value=''; a2.value=''; a3.value=''; a4.value=''; }

the "c" (this.getfield("q1")) is the textfield that i want to set only accept number and comma (,) symbol

after i'm adding your code,  the "else if" code after did not work anymore

i hope you can help me with this


thank you,
kurt

try67
Community Expert
Community Expert
April 11, 2018

I don't understand what the rest of your code is supposed to do... Why are you checking the values of all of these other fields?