Regular expressions

Conditional Fields PRO allows you to use regular expressions for the values in any condition. In it’s most straight-forward form, you can just enter the regular expressions as plain text.

Because regular expressions can be hard to manage and debug, the plugin makes it possible to create and use some preset regular expressions. To check which presets are available and to add your own, go to Contact > Conditional Fields in the WP backend.

To add a new preset, simply type the label you want to use (in this case “streetaddress”) in the left field. In the right field, enter the regular expression. Make sure to save your changes.

Now that you have created your own preset, next time you create a condition with a regular expression, you can simply type the label in the field. An auto-complete dropdown will appear from which you can select the desired regular expression.

Note: if you would like to make your conditions even more dynamic, you can also use custom javascript functions.

Example: Check if a value looks like a steet address

Form

    Please enter your street and house number

    Thanks. Now please enter the name of your city.

    Form Code

    <p>Please enter your street and house number</p>
    [text streetaddress]
    [group a]
      Thanks. Now please enter the name of your city.
      [text city]
    [/group]

    Conditional Fields (Text)

    show [a] if [streetaddress] equals (regex) "^[a-zA-Z ]+ [0-9]+$"