Copy link to clipboard
Copied
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
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!");
}
}
Copy link to clipboard
Copied
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!");
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
i'm sorry mr try67,
lets forget about the whole code and focus on this 2 line code :
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=''}
the bold one is your's and the rest is mine
the "C" is the textfield that i want to set only can accept number and comma symbol.
the "else if" code function is when i fill the C textfield with "0" it'll pop up app alert that says "Quantity cannot 0"
when i use this code :
"if(Math.floor(event.value) != event.value) { event.rc = false; app.alert("Enter integr values only"); c.value=''; }
else if (c.value=='0'){app.alert("Quantity cannot 0!!", 0); c.value=''}"
the "else if" code is work but the "C" textfield cannot accept the comma symbol.
thank you for your help
kurt
Copy link to clipboard
Copied
The rest of the code is important, though. What is the "c" variable pointing to? Should it be the new value of this field?
Copy link to clipboard
Copied
hello mr try67
the "c" variable pointing to a quantity of an item, so it cannot be 0 or minus -
i want to set "c" only can accept numeric and comma symbol, but cannot accept 0 or minus
thanks for your help
Copy link to clipboard
Copied
But is it the field that is being validated? If so, you need to access the new value using event.value, not using this.getField("...").value ...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!");
}
}
Copy link to clipboard
Copied
thank you mr try67
that's what i wanna do with my pdf form
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Setting event.rc to false rejects the new value entered by the user and reverts the field to its original state.