Deeper Email validation with Laravel Rules

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.