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, Macintosh, Windows

Views

237

Likes

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

Adobe Community Professional , 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...

Likes

Translate

Translate
Adobe Community Professional ,
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;

}

Likes

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

Likes

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
Adobe Community Professional ,
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.

Likes

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
Adobe Community Professional ,
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)?

Likes

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
Adobe Community Professional ,
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";

}

Likes

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!

Likes

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