Validation in Formit with regex?

Hi all.
I have a contact form with a simple spam protection via a maths task.
In German: “Was ergibt 2 und 5” (What results in 2 and 5).
The possible answers should be “7”, “sieben” or “Sieben” (means the result can be written as a number or as text).

I don’t know enough about regex to define a suitable value for
secure:regexp=^…^

Any hints would helpful. Thanks!

A value like this might work for your use case:

&validate=`secure:regexp=^/\A\s*(7|sieben)\s*$/i^`

To understand this regular expression better, you could use a website like https://regex101.com/ and copy the expression /\A\s*(7|sieben)\s*$/i (without the surrounding ^ characters) into the field on the site.


Alternatively you could write a custom validator for this, if you don’t want to use regular expressions.

Thanks for this quick solution. This expression is very useful because I have some sites with different forms but the same spam protection with different tasks/results.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.