# Form Email Validation - Block all providers except one

**URL:** <https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088>\
**Category:** APIs & Integrations\
**Tags:** forms, contacts\
**Created:** [April 23, 2019, 7:11pm UTC](https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088 "2019-04-23T19:11:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [April 23, 2019, 7:11pm UTC](https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088/1 "2019-04-23T19:11:32Z")

</div>

Hi,

I’ve created a form with 2 fields ie: Email and Name.

I would like to only accept submissions if the email address contains “@marc.com” and restrict all other domains (not just free providers) and display an error if the email entered is eg. @gmail.com, [yahoo.com](http://yahoo.com), etc

From what I gather, the form options only allow me to block domains and not block all and only allowlist a certain domain…

Any ideas or suggestions on how to implement this using onFormSubmit or any other methods?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![cbarley](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cbarley/32/82559_2.png) [@cbarley](https://community.hubspot.com/u/cbarley)\
**Post date:** [April 24, 2019, 5:45pm UTC](https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088/2 "2019-04-24T17:45:51Z")

</div>

Hi @Anonymous ! While we can tackle this in [the opposite way in the HubSpot tool](https://knowledge.hubspot.com/articles/kcs_article/forms/block-form-or-pop-up-form-submissions-from-specific-email-domains), i.e. _block_ certain domains, we don’t have a way to _allow_ only a certain domain to be submitted. For this, you’d have to use some JavaScript to check whether or not the domain name matches the one you’d like to allow.

Something like this would work inside the [**onFormSubmit** callback function](https://developers.hubspot.com/docs/methods/forms/advanced_form_options) on the form, or you could utilize [global form events](https://developers.hubspot.com/global-form-events) (onFormSubmit again) in order to tackle this issue. Something like this would work:

```auto
window.addEventListener('message', event => {
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
 // VALIDATE EMAIL AND SUBMIT
 }
});

```

Let me know if you have questions! Happy to see if I can find any alternatives if this won’t work!

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [May 3, 2019, 11:27am UTC](https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088/3 "2019-05-03T11:27:16Z")

</div>

Apologies for my late response@cbarley but you are a legend thank you so much!

---

<div class="post-metadata">

**Author:** ![geekbleek](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/geekbleek/32/73373_2.png) [@geekbleek](https://community.hubspot.com/u/geekbleek)\
**Post date:** [June 30, 2020, 11:16am UTC](https://community.hubspot.com/t/form-email-validation-block-all-providers-except-one/14088/4 "2020-06-30T11:16:22Z")

</div>

This actually doesn’t work - the onFormSubmit method is non-blocking as indicated here:

[https://428357.hs-sites.com/global-form-events?\_\_hstc=20629287.9f00fb7b5f007831e42b7371f39b04a5.1576171415885.1593468713486.1593515539586.60&\_\_hssc=20629287.3.1593515539586&\_\_hsfp=2859492949](https://428357.hs-sites.com/global-form-events? __hstc=20629287.9f00fb7b5f007831e42b7371f39b04a5.1576171415885.1593468713486.1593515539586.60&__ hssc=20629287.3.1593515539586&__hsfp=2859492949)

So the form will still continue to submit, even though that event is called. We still need a method to filter forms by domain.
