Blocking gmail.com emails from form submissions

Is there a way to require form submissions to NOT use personal email addresses (those from gmail.com, outlook.com and other domains)?

I am getting a lot of spam even with Recaptcha. They all are coming from gmail.com or outlook.com domains.

Thanks

3 Likes

Hi Andrey, welcome to the forum :webflow_heart:

You will have to use custom code for that.
Something like that:

<script type="text/javascript">
    $(document).ready(function(e) {
        $('#submit-button-id').click(function() {
            var email = $('#email-field-id').val();
            var reg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!yahoo.co.in)(?!aol.com)(?!abc.com)(?!xyz.com)(?!pqr.com)(?!rediffmail.com)(?!live.com)(?!outlook.com)(?!me.com)(?!msn.com)(?!ymail.com)([\w-]+\.)+[\w-]{2,4})?$/;
            if (reg.test(email)) {
                return 0;
            } else {
                alert('Please Enter Business Email Address');
                return false;
            }
        });
    });
</script>
7 Likes

Hi Aviv,

Thanks for your help.

Can this code be added in the Webflow UI (I am not developer)?

Perhaps via the Custom Attributes section in the text field setting of the email form…

Thanks, Andrey

@akisselev, this code can be placed on the page where your form is at or under the custom code section of your Page Settings.

This would not be an attribute on the form. Since you are specifically telling the form to reject certain email extensions.

Hope that helps,
Brandon

1 Like

Hi there Avivtech,

This looks like something I need as well. Is there a way to modify that script so that the form only allows a select few extensions, rather than list all the extensions we don’t want to let through?

Cheers
Grant

Hey @grantsenior,

Yea, change the long VAR line with all the email domains to a shorter one.
Check this out:

3 Likes

@QA_Brandon @avivtech Hey Guys, I tried the code by adding it to an existing form and it doesn’t work for some reason. I tried pasting it in the head section, body section as well as matching the fields/submit id’s with the ones on the code. No luck, what could be gone wrong?

Hey @HamzaL,
Can you share a read-only link?

58%20PM
@avivtech I did match the ID’s as email for the email field ID and submit to the btn ID similar to the code.

I won’t be able to really debug the problem without a read-only link and a link to the published site… :confused:

@avivtech Hey man, for some reason I was missing a letter in the ID name, so that part is fixed now.
Is there a way to show the alert message using the Webflow default error message area, instead of using the browser default alert message box?

Yes, but it is a completely different function… You’ll have to use something else then the ‘alert’ method.

@avivtech So basically using the same script blocking personal emails like gmail, but uses Webflow default Error and Success with that script. Any changes to be made to that JS script? Your help is highly appreciated :pray:

<script type="text/javascript">
    $(document).ready(function(e) {
        $('#submitform').click(function() {
            var email = $('#email').val();
            var reg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!yahoo.co.in)(?!aol.com)(?!abc.com)(?!xyz.com)(?!pqr.com)(?!rediffmail.com)(?!live.com)(?!outlook.com)(?!me.com)(?!msn.com)(?!ymail.com)([\w-]+\.)+[\w-]{2,4})?$/;
            if (reg.test(email)) {
                return 0;
            } else {
                alert('Please Enter Business Email Address');
                return false;
            }
        });
    });
</script>

Not sure what is the question :sweat_smile:

@avivtech Sorry for the confusion :smiley:
My question is: Can you point out what should I do to use the same “blocking gmail script” and have webflow’s default message showing the error message instead of using the browser default alert message box?

oh…
That’s a bit more than pointing out :smiley:
I suggest that you look for a front-end developer here

@avivtech I thought It’s not complicated and will be solved by only changing the ‘alert’ method to something else that will trigger webflow’s error message to show that instead of the browser one. Thanks man!

Trying to use this script too and I cannot get it to work either.

Script is currently active on my frontpage and I’ve tried blocking the domain “urhen.com”.

Here’s a read only link

Any idea what might be going wrong?

@jwb

There’s a red dot for some reason in your code. remove it and I think you’re good to go!

1 Like

Oh man, I really hoped this silly mistake of my own was all I had to fix. Unfortunately it didn’t seem to do the trick :-/