Email Domain Verification on Form Submissions

Many businesses want to restrict their content and communication to contacts with business email addresses (i.e. no free accounts like Gmail). Typically, willingness to share a business email indicates at least a slightly better lead than someone only willing to share a personal address. At a minimum, it’s most likely someone more genuinely interested in the content for business purposes. As another use case, businesses may want to restrict competitors from easily accessing their content.

Using some simple Javascript, Mautic users have the ability to restrict contacts from using specific email domains on their forms.

Step 1: Build your form.

Step 2: Use the Manual Copy for the form code.

Manual Copy

Copy the code in the top box into the head or body. Then, copy the code in the bottom box into the body of the page where you want the form to appear.

Step 3: Within the form code (from the bottom box), find the opening <form> tag and add onsubmit=”validateForm()“.

Step 4: Add the following script underneath the closing </form> tag but before the last </div> tag:

<script>function validateForm() {var emailAddressField=document.getElementById(‘mauticform_input_formname_emailfieldname‘);var regex = new RegExp(/@gmail|@yahoo|@restricteddomain/);if (emailAddressField.value.match(regex) != null){alert(“Please submit a work email address.”);event.preventDefault();window.history.back();return false;}return true;}</script>

Note: Change “formname” to the HTML label for your form’s name and email field (replacing ’emailfieldname’). You can find the full ‘mauticform_input…’ text within the manual copy of the form code.

You’ll also want to replace “gmail”, “yahoo”, and “restricteddomain” with the domains you want to disallow. Add as many as you’d like, separated by pipes (|).

You may also edit the alert message.

It’s possible that your page editor will add <br /> tags within the validateForm function. If that happens, delete those tags as they’ll cause the function to be “undefined”.

Step 5: Test your form!

Keep in mind that if you make changes to your form, you’ll need to re-copy the form code from Mautic onto your page. The manual copy method, which is required for more advanced form functionalities like this, does not automatically update changes from Mautic.