Skip to main content
Inspiring
January 15, 2019
Answered

Field value with any number and any text

  • January 15, 2019
  • 1 reply
  • 845 views

Dear Acrobat scripters,

Is there an way you can get any number and than text in  this.getField.value . Do I have to do that with RegExp?

if (this.getField("field1").value = 'ANY NUMBER + ANY TEXT') {

DO SCRIPT;

} else {

DO SCRIPT;

}

Already thanks for the help!

Greetings

This topic has been closed for replies.
Correct answer try67

I think I misunderstood what you want to achieve. Do you want to test if the string has any numbers in it and any "text" (ie, letters)?


If that's what you're after it would require using Regular Expressions, as mentioned above.

Try this code:

var v = this.getField("01_pallet_2_test").valueAsString;

var numbersRegExp = new RegExp("\\d", "g");

var lettersRegExp = new RegExp("[a-z]", "gi");

if (v=="") {

    event.value = "";

} else if (numbersRegExp.test(v) && lettersRegExp.test(v)) {

    event.value = "number with text";

} else if (numbersRegExp.test(v) && !lettersRegExp.test(v)) {

    event.value = "only number";

} else if (!numbersRegExp.test(v) && lettersRegExp.test(v)) {

    event.value = "only text";

} else if (!numbersRegExp.test(v) && !lettersRegExp.test(v)) {

    event.value = "Other";

}

1 reply

try67
Community Expert
Community Expert
January 15, 2019

Sure, like this:

if (this.getField("field1").valueAsString == "1234ABC") {

    // DO SCRIPT;

} else {

    // DO SCRIPT;

}

Inspiring
January 15, 2019

Hey thank you for the fast reply!

I made an little test:

if (this.getField("01_pallet_2_test").valueAsString == "1234ABC") {  

event.value = ("number with text");

} else {  

event.value = ("only number");

}

When the user types "9.99" the field comes with "only number"

But when the user types "3 voor" it still comes with only number while the script has to fill it with "number with text".

What do I wrong?

Greetings

Bernd Alheit
Community Expert
Community Expert
January 15, 2019

Nothing is wrong. "3 voor" is not the same as "1234ABC".

May be that you need a RegExp.