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
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
Copy link to clipboard
Copied
Sure, like this:
if (this.getField("field1").valueAsString == "1234ABC") {
// DO SCRIPT;
} else {
// DO SCRIPT;
}
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
Copy link to clipboard
Copied
Nothing is wrong. "3 voor" is not the same as "1234ABC".
May be that you need a RegExp.
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)?
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";
}
Copy link to clipboard
Copied
Yes thank you!
I knew it has to work with RegExp but didn't know how.
Again, thank you very much!