Skip to main content
Participating Frequently
April 9, 2019
Answered

Check texbox for specific word

  • April 9, 2019
  • 1 reply
  • 723 views

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

This topic has been closed for replies.
Correct answer Thom Parker

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 ...

}

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
April 9, 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 ...

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
April 9, 2019

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!!