How can I add code to Webflow to require a valid domain ending in email submissions?

TL;DR
  • Add a JavaScript snippet to Webflow's custom code to validate email submissions, replacing @yourdomain.com with your desired domain.
  • Save your changes, publish the site, and test the validation by submitting forms with different email addresses.

To ensure that your Webflow form submissions are validated for a specific domain ending in email addresses, you will need to add a custom code snippet to your Webflow project.

1. Access the Project Settings

  • Go to Project Settings in your Webflow dashboard.
  • Navigate to the Custom Code section.

2. Add Custom Validation Code

  • In the Footer Code area, paste the following script after ensuring it's customized with your desired domain ending:

  

  ```javascript

  <script>

  document.addEventListener('DOMContentLoaded', function() {

    const form = document.querySelector('form');

    if (form) {

      form.addEventListener('submit', function(event) {

        const emailField = form.querySelector('input[type="email"]');

        const emailPattern = /.+@yourdomain.com$/;

        if (emailField && !emailPattern.test(emailField.value)) {

          event.preventDefault();

          alert('Please enter a valid email address ending with @yourdomain.com');

        }

      });

    }

  });

  </script>

  ```

  • Replace @yourdomain.com with the domain ending you want to validate against.

3. Save and Publish Your Changes

  • Save the changes to your custom code.
  • Publish your site to ensure the changes take effect.

4. Test the Validation

  • Go to your published Webflow site.
  • Submit a form using different email addresses to ensure that only the specified domain ending is accepted.

Summary

To validate email submissions for a specific domain in Webflow, add a JavaScript snippet in the project settings that checks the email pattern during form submission. Customize the domain ending within the code, then save, publish, and test your site.

Rate this answer

Other Webflow Questions