APIs & Integrations

Jonathan_Marsan
Member

Regex to Validate Email Addresses

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

3 Replies 3
Jonathan_Marsan
Member

Regex to Validate Email Addresses

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:

0 Upvotes
JamiesonC
Participant

Regex to Validate Email Addresses

@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
0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

Regex to Validate Email Addresses

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

How Does HubSpot validate email addresses?

HubSpot uses a few rules to validate the format of email addresses in the Contacts system.

0 Upvotes