Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Custom Validation script for range AND multiple value

New Here ,
Feb 03, 2017 Feb 03, 2017

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!

TOPICS
PDF forms
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 03, 2017 Feb 03, 2017

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;

    }

}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2017 Feb 03, 2017

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;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2017 Feb 03, 2017
LATEST

Hi! I had never heard about modulo! It works perfectly! Thanks so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines