In Visibility Rules, “Contains” means a regular expression, not a simple string match

SanfordWhiteman
Level 10 - Community Moderator
Level 10 - Community Moderator

Little-publicized, to the point that even Support might not be in the loop: the Visibility Rule Contains operator does allow multiple values.

The Contains value is interpreted as a full-fledged regular expression, so use the pipe character | to separate sub-values:

ss

In fact, because of this unexpected/undocumented power, you must anchor an expression to avoid surprises:

^(TX|FL|PA)$ 

Otherwise, it's doing a partial match of the full value against each of your pipe-delimited alternatives. This might not be a problem on your forms right now, but if it becomes a problem, you wouldn't know about it immediately.

For example, if you were using uppercase state names, then

     Contains KANSAS|IDAHO

would match both ARKANSAS and KANSAS, and you should use

     Contains ^(KANSAS|IDAHO)$

instead.

You can also of course do more fancy matches with regexes if you want. And Not Contains is also a regex!

3950
8
8 Comments
KellyJoHorton
Level 3 - Champion Alumni

You just made my day. :^)

Jace_Garside1
Level 2

I just tried implementing this to have rich text appear if a generic email is entered - sort of a quasi way to discourage personal email addresses without completely denying them. But it only recognizes the first value I have listed.  Any thoughts?

Jace_Garside1_0-1618613225064.png

 

SanfordWhiteman
Level 10 - Community Moderator

That particular regex isn't what you want because it's checking if the value begins with the email domain. See my answer on your new thread: https://nation.marketo.com/t5/Product-Discussions/Visibility-Rules-with-Multiple-Values-within-Crite...

BenCirillo
Level 2

Is there an expression that would work if I wanted to do the opposite: display values if Value A and Value B are true. 

 

I'm trying to do something like this (not this, but like this): 

Q: What topics are you generally interested in? 

(checkboxes)

  • Sports
  • Music
  • Theater

Then the followup question: 

What topics are you specifically interested in? (also checkboxes)

If you chose Sports only, you see: 

  • Football 
  • Baseball 
  • Soccer

If you chose Music only, you see: 

  • Rock
  • Opera
  • Jazz

If you chose Sports and Music, you see: 

  • Football
  • Baseball
  • Soccer
  • Rock
  • Opera
  • Jazz

Again, not a real example, but the concept is basically giving people a short list of broad categories to choose from, and then only as many specific topics as are relevant to them, to keep the form only as long as it needs to be. 

SanfordWhiteman
Level 10 - Community Moderator

I'm thinking yes, with a regex matching on the semicolon-delimited string you get from Checkboxes ("sports;theater"). But haven't tried this exact method.

AnthonyS_
Level 1

@SanfordWhiteman Is there a way to say search for two words that are not directly after each other but in the same string? I tried doing the above but that didn't work. 

 

If I had values like this:

Running;Long Jump;Triple Jump;

Running;Shotput;Triple Jump

Shotput;Long Jump

 

And I wanted to show a checkbox for if there selection contained Running and Jump, is that possible? I've tried using regex like this .*Running.*\.*Jump.*$ but Marketo doesn't like it.

SanfordWhiteman
Level 10 - Community Moderator

You definitely wouldn't want to escape the dot (\.) as that means a literal dot. But there aren't any dots in your sample strings.

 

You can use:

Running;.*Jump

but if this is a Checkboxes set or multi-Select it's clearer to include the explicit variations, since they're not infinite:

Running;.*(Triple Jump|Long Jump|High Jump)

 

Note this isn't really the same as checking against a list, as it relies on a specific order, "Running" always coming first. But if you ensure that order on the form, it's fine.

AnthonyS_
Level 1

Thanks so much!

 

I've ensured the order of the field so this works perfectly!