Expand my Community achievements bar.

Need to find a specific word in a Text Field

Avatar

Former Community Member

I have a text field and I need to be able to perform a function if that field contains (not equals) the word "Excel". Textfield contains the word Excel

My sample is below

if (this.rawValue== "Excel") <---- instead of = I want something using wildcards before and after the word "Excel"

     {

     Then do something

     }

Else

     {

     Do something else

     };

4 Replies

Avatar

Level 10

Hi,

you can use a regular expression for this task.

if (this.rawValue.match(/\s+Excel\s+/g)) {

          ...

} else {

  ...

}

Avatar

Former Community Member

This only seems to work if I have a white space before and after the word "Excel" I need something that would work like *Excel*.

Avatar

Level 2

Try:

if (this.rawValue.match(/Excel/gi) ...

Avatar

Former Community Member

Thanks guys, you pointed me the right direction. This is what I have that seems to be working

if (this.rawValue.match(/.*Excel.*/))