Skip to navigation
Email validation function with dns check in php
15.09.15
function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex): $isValid = false; else: $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64): $isValid = false; elseif($domainLen < 1 || $domainLen > 255): $isValid = false; elseif($local[0] == '.' || $local[$localLen-1] == '.'): $isValid = false; elseif(preg_match('/\\.\\./', $local)): $isValid = false; elseif(!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)): $isValid = false; elseif(preg_match('/\\.\\./', $domain)): $isValid = false; elseif(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))): if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))): $isValid = false; endif; endif; if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))): $isValid = false; endif; endif; return $isValid; }
http://www.linuxjournal.com/article/9585?page=0,3
Reply
Anonymous
Information Epoch 1732580321
Design for visibility.
Home
Notebook
Contact us