AppsScriptPulse

Check the domain of an email address by regex

Compare a number of email addresses and check their domains against one you are filtering for via a regular expression.

Screenshot of email addresses in a Google Sheet cell

Screenshot of email addresses in a Google Sheet cell

The following Google Apps Script is designed to use a regular expression (regex) to confirm if an email address domain matches one we specify eg: @hotmail.co.uk, @gmail.com, @outlook.com

I developed the code so I could screen email addresses to make sure they only came from within the institution – otherwise it would have broken the tool I was developing for creating Zoom meetings. The email addresses in this example are all stored in one cell in a Google Sheet and are separated via a comma and a single space.

Source: The Gift of Script: Check the domain of an email address by regex

1 comment for “Check the domain of an email address by regex

  1. 3 August, 2021 at 18:5423

    For Google Sheets formula/function fans you can achieve something similar with =ARRAYFORMULA({TRANSPOSE(SPLIT(A2,", ")),REGEXMATCH(TRANSPOSE(SPLIT(A2,", ")),"@random.com")})

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to Apps Script Pulse...