Deeper Email validation with Laravel Rules

Sastha K L
Aug 21, 2018 · 1 min read

Laravel inbuilt validation works great for email validation. But its functionality limits itself to checking format of given string.

A email validation system would be more effective if it can help check for following

  • Allow only emails from domains which actually exists
  • Restrict emails from temporary email domains
  • Check for top level domains

Check Domain Exists

Using Laravel-Ping, we can filter out incorrect domain names in email.

$domain = explode(‘@’, $value)[1];
$health = Ping::check($domain);

if($health !== 200) {
return false;
}

Restrict Temporary Email Domains

List of popular temporary email domains are available here.

Checking email against these list can help filter out temporary email domains.

$domain = explode(‘@’, $value)[1];
return !in_array($domain, [Temp Email domains]);

Check for top level domains

Check if “.com” in example@email.com is part of top level domain list

List of top level domains is available at icann.org

Source : Laravel Rules

Note: Even-though this is better than inbuilt Laravel validator, Its not 100% efficient. A email which is not in the list of temp domain are still accepted.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade