Check texbox for specific word

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

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

93

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

Check texbox for specific word

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

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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

}

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

94

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
Apr 09, 2019 0
Adobe Community Professional ,
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 ...

}

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
Reply
Loading...
Apr 09, 2019 0
Apr 09, 2019

Copy link to clipboard

Copied

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

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
Reply
Loading...
Apr 09, 2019 0