Regular Expressions for Webform Validation

Last updated on
30 April 2025

Here are some example regular expressions which might be useful in Webform Validation. Thanks to rbrownell.

"This"

^(?=.*?\bRehearsal\b).*$

Validates for the word Rehearsal.

"This or This or This"

^(?=.*?\b(Rehearsal|Matinee|Performance)\b).*$

Validates for at least one of the words Rehearsal, or Matinee, or Performance.

"This and This and This"

^(?=.*?\bRehearsal\b)(?=.*?\bMatinee\b)(?=.*?\bPerformance\b).*$

Validates only if all the words Rehearsal, Matinee, and Performance are present.

"This or This, This or This, and This"

^(?=.*?\b(Load In|Setup)\b)(?=.*?\b(Load Out|Teardown)\b)(?=.*?\bPerformance\b).*$

Validates only if either Load In or Setup is present, and Load Out or Teardown is present and only if Performance is present.

"Not This"

^((?!Matinee).)*$

Validates only if Matinee is not present.

"Not This or This or This"

^((?!Rehearsal|Matinee|Performance).)*$

Validates only if neither Rehearsal, nor Matinee, nor Performance are present.

"This, This or This, and This or This, but Not This or This

^(?=.*?\bPerformance\b)(?=.*?\b(Load In|Setup)\b)(?=.*?\b(Load Out|Teardown)\b)((?!Matinee|Rehearsal).)*$

Validates only if Performance, and Load In or Setup, and Load Out or Teardown is present but won't validate if Matinee or Rehearsal is present.

Help improve this page

Page status: Not set

You can: