Hopefully this will be an easy one. I want to write an IF statement to determine if a field contains a certain value. I have a field that users have populated with data using checkboxes on a form, so, for example the field “colors” = Blue Red Orange. My code looks something like this:
if (colors == "Blue")
{
//do something
}
But this only returns true if ONLY blue is selected. How can I determine if this field “contains” blue regardless of what other colors may be selected. I tried this to no avail:
I had a similar problem searching Tickbox data and completely overlooked ‘indexOf’. Your suggestion is sooo much more elegant than my clunky workaround
"The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.
Perform a global, case-insensitive search for "ain":
var str = "The rain in SPAIN stays mainly in the plain";
var res = str.match(/ain/gi);
The result of res will be:
ain,AIN,ain,ain