Regex to Validate Email Addresses

batch

#1

Hey!

I’m uploading contact properties to Hubspot in batches through the API (http://developers.hubspot.com/docs/methods/contacts/batch_create_or_update).

Since the whole upload gets cancelled anytime there is an invalid email, I’d like to filter our invalid emails with the regex that Hubspot uses to validate emails. Is this available somewhere? If nt, can you please share? :slight_smile:

Thanks,

Jonathan


#2

@Jonathan_Marsan you may not get the exact HubSpot regex, but you can start with a very simple expression, see if it eliminates your upload failures, and iterate from there.

A very simplistic starting point:

^[^@]+@[^\.]+\..+$

This will detect the most common email irregularities:

  1. Blank email
  2. Missing @
  3. Missing TLD

#3

@Jonathan_Marsan you can find more details for the rules that we use to validate emails here:


#4

Thanks @Bistream630 and @dadams

I ended using the Validate_email Python package, but we’ve still been getting some errors.
I think this list, https://data.iana.org/TLD/tlds-alpha-by-domain.txt, found on the page referenced by dadams will solve the last bit of problems. :+1: