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

Check texbox for specific word

New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

I am trying to figure out how to check a certain textbox contains a certain word in either upper or lowercase (XPO). If it does, then perform one action. If not then perform a different action, below is the code i currently am working with but it dosent seem to work.

var cCustomerName = this.getField("CUSTOMER NAME").value;

if (cCustomerName == "XPO"||"xpo"){

ccAddress1 = ("dan.somename@somewhere.com" + "; " + "eps@somewhere.com" + "; " + "mark.b@somewhere.com" + "; " +"jeff.s@somewhere.com")

}

else

TOPICS
Acrobat SDK and JavaScript , Windows

Views

460

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 , Apr 09, 2019 Apr 09, 2019

The best way to perform a test on text, is with a Regular Expression:

https://acrobatusers.com/tutorials/text-matching-regular-expressions

If XPO is this only word in the field, then this test will work

if(/^xpo$/i.test(cCustomerName))

{

.. Do stuff ...

}

But if XPO is only part of the text, then this will work

if(/xpo/i.test(cCustomerName))

{

.. Do stuff ...

}

If XPO needs to be a whole word in the text, then use this

if(/\wxpo\w/i.test(cCustomerName))

{

.. Do stuff ...

}

Votes

Translate

Translate
Community Expert ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

The best way to perform a test on text, is with a Regular Expression:

https://acrobatusers.com/tutorials/text-matching-regular-expressions

If XPO is this only word in the field, then this test will work

if(/^xpo$/i.test(cCustomerName))

{

.. Do stuff ...

}

But if XPO is only part of the text, then this will work

if(/xpo/i.test(cCustomerName))

{

.. Do stuff ...

}

If XPO needs to be a whole word in the text, then use this

if(/\wxpo\w/i.test(cCustomerName))

{

.. Do stuff ...

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

LATEST

Thanks Thom, this seems to work out well. I would have never figured it out and it works for any combination whether it be caps or lowercase. Perfect!!

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