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
  • 10670 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 25, 2018

hello mr try67

i want to ask you again about this topic

i know it's already answered but i need your help

so i put your code in the custom validation script and it work fine. the code are :

if (event.value) { 

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

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

}

it work fine but i want to add something in that code.
so what i want to do is when i input a wrong value into the text field i want it to pop app alert "incorrect value" and i want it to erase the wrong value in the text field.

so i add this to your code :

if (event.value) { 

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

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

}

but the code did not erase the wrong value, it just pop up an alert message.

i hope you response to this question

thank you for your help

try67
Community Expert
Community Expert
April 25, 2018

Setting event.rc to false rejects the new value entered by the user and reverts the field to its original state.