The common point between new accounts signing-up to your service and subscribing to your mailing list is that they identify themselves with an email address.
If we were in a perfect world, all the email addresses would be and remain valid, but with time mailboxes got closed, and the addresses in your database become invalid. There is also always the possibility for people to make a typo while entering their email addresses, and some of them may also voluntarily use a fake address.
Don't reinvent the wheel.
Abstract's APIs are production-ready now.
Abstract's suite of API's are built to save you time. You don't need to be an expert in email validation, IP geolocation, etc. Just focus on writing code that's actually valuable for your app or business, and we'll handle the rest.Get started for free
This is why a list must regularly be cleaned and invalid addresses deleted to preserve its quality, optimize your mailings' deliverability rate, and increase your email marketing campaigns' success.
You may want to implement a simple email address format validator on the client-side, so when your visitors enter their email address in your forms, the address format gets validated before reaching your server.
Using regular expression is probably the best approach. Let’s see the most simple syntax:
This is a breakdown of the regular expression /^\S+@\S+$/:
This regular expression verifies that the email address contains no space and is composed of one or more characters followed by the "@" sign followed by one or more characters.
This seems to be enough for most email addresses, but in reality, it would reject some valid email because whitespace characters are actually allowed as long as they are escaped. For example, the following is a valid email and would be rejected by the code mentioned above:
At this point, you may want to continue in the same direction and try to use an email regex guide to consider every case.
For example, you could try to match escaped or quoted whitespaces. If you do so, you will also have to implement all specific cases, including Unicode characters and much more. Then you will end up with a regex impossible to debug and particularly impossible to test.
As demonstrated above, efficiently verifying an email address format by yourself is not an easy task.
The only reliable way to verify an email address is to have the recipient’s SMTP server to validate it. And to do so, an email validator would need to go through the following steps: validate the domain name, search through its MX records, and query the SMTP servers.
If you're looking to simplify the process of email validation, you can review and choose one of the best email validation APIs to help you out.
Abstract provides an email validation API that solves this problem and takes away the complexity of this task. With a single call, you can validate the address format, check if the email is hosted on a free service if it is a disposable email, and much more.
After creating a free account at Abstract, which automatically generates your private API key, you can call the API and validate your visitors’ email addresses very easily.
This is an example of a response: