• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Field value with any number and any text

Participant ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

498

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 15, 2019 Jan 15, 2019

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

...

Votes

Translate

Translate
Community Expert ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

Sure, like this:

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

    // DO SCRIPT;

} else {

    // DO SCRIPT;

}

Votes

Translate

Translate

Report

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
Participant ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

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

May be that you need a RegExp.

Votes

Translate

Translate

Report

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 ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

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)?

Votes

Translate

Translate

Report

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 ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

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";

}

Votes

Translate

Translate

Report

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
Participant ,
Jan 15, 2019 Jan 15, 2019

Copy link to clipboard

Copied

LATEST

Yes thank you!

I knew it has to work with RegExp but didn't know how.

Again, thank you very much!

Votes

Translate

Translate

Report

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