Copy link to clipboard
Copied
Hi! My question is about the custom validation script in the Validate window in an Acrobat Form. I am working with Acrobat DC. (sorry if my english is not clear, I usually speak french)
I have a field where the value needs to be only between 100 and 400 000, and also needs to be a multiple of 100. For example, I can only put 100, 200, 300, etc. until 400 000.
I found a script where i can put the different value possible, but the thing is, I don’t want to write every number possible up to 400 000. It will take too much time. Here is my script for the moment, giving only 3 possible values:
event.rc = true;
if (event.value != "100" && event.value != "200" && event.value != "300")
{
app.alert("La valeur entrée doit être d'un minimum de 100 et un multiple de 100.");
event.target.textColor = color.red;
}
else
{
event.target.textColor = color.black;
}
So is there a script that i would not have to write every number possible?
Thank you!
Copy link to clipboard
Copied
Have you ever heard of the mathematical operator called modulo? It's like the division operator, only it returns the remainder of the division operation, instead of the full value. You can use this operator to easily achieve what you want by "modding" the value by 100 and seeing if the result is 0. If so then you know it's a multiple of 100. This operator is represented in JavaScript by the "%" symbol.
So your code can be something like this:
if (event.value) {
var v = Number(event.value);
if (v < 100 || v > 400000 || v%100!=0) {
app.alert("La valeur entrée doit être d'un minimum de 100 et un multiple de 100.");
event.target.textColor = color.red;
} else {
event.target.textColor = color.black;
}
}
Copy link to clipboard
Copied
Have you ever heard of the mathematical operator called modulo? It's like the division operator, only it returns the remainder of the division operation, instead of the full value. You can use this operator to easily achieve what you want by "modding" the value by 100 and seeing if the result is 0. If so then you know it's a multiple of 100. This operator is represented in JavaScript by the "%" symbol.
So your code can be something like this:
if (event.value) {
var v = Number(event.value);
if (v < 100 || v > 400000 || v%100!=0) {
app.alert("La valeur entrée doit être d'un minimum de 100 et un multiple de 100.");
event.target.textColor = color.red;
} else {
event.target.textColor = color.black;
}
}
Copy link to clipboard
Copied
Hi! I had never heard about modulo! It works perfectly! Thanks so much!

