Form Email Validation - Block all providers except one

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, 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

Hi @Anonymous ! While we can tackle this in the opposite way in the HubSpot tool, 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 on the form, or you could utilize global form events (onFormSubmit again) in order to tackle this issue. Something like this would work:

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!

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

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

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