MODX Community

[SOLVED] Validation via regex in email field fails

Hi everyone.
According to this thread Formit how to block certain domains I tried to block some domains from sending formit mails.
But it doesn’t work, no matter if I enter allowed or not allowed domains in the email field, the form will be sent.

MODX is the current version 2.8.1
PHP is 7.3

The validation (extract):
&validate= …, email:email:required:regexp=^/^((?!yahoo\.com|gmail\.com|aol\.com).)*$/i^, …

The corresponding label and input field (in German):
<label for="email">E-Mail*</label>[[! korrekt ausfüllen]] <input type="email" class="form-control" id="email" name="email" placeholder="E-Mail-Adresse*" value="[[!]]">

All form mails are sent for all mail address inputs if mail format is valid.

I checked the regex via, the result is valid.
Any suggestions? Thanks!

I think the problem is, that the character ^ (caret) is both used as a delimiter around the regex expression and as the “start of string anchor” in the regular expression.

In the code there is this line to get rid of the delimiters, but it also deletes the anchor in the regex.

Your regular expression


gets converted into


and therefore doesn’t work anymore.

You probably have to write a custom validator to get around this problem.
Or maybe you can just change the regular expression:


Thanks for your suggestion. I can’t write a custom validator and I don’t understand regular expressions good enough but I give your last code line a try. The regex feature in formit seems to be a bit tricky becaus of the use of carets instead of backticks and the use of carets in regex syntax. You CAN use regex but you can’t use it simple because of this restrictions.

Ok, I’ll check this and give a reply.

Wow, it works! Many thanks! :+1: