\(\),;:\"\[\]\@'; $mailboxpattern = '/^[' . $mbox . ']+(\.?[' . $mbox . ']+)*$/'; $dom = "a-z0-9"; $root = "a-z"; $labelpattern = '/^[' . $dom . ']+(-[' . $dom . ']+)*$/i'; $rootpattern = '/^[' . $root . '][' . $root . ']+$/i'; //$pattern = '/^([' . $mbox . ']+(\.?[' . $mbox . ']+)*)\@([' . $dom . ']+([.-]?[' . $dom . ']+)*\.[' . $root . ']{2,4})$/i'; if(preg_match($mailpartpattern, $emailaddress, $mailparts)) { $mailbox = $mailparts[1]; $domain = $mailparts[2]; // match the mailbox portion against the regex if(! preg_match($mailboxpattern, $mailbox)){ return false; } // OK, now, the domain cannot exceed 255 chars if(strlen($domain) > 255) return false; // Break the domain portion into "labels" on the dots. $labels = explode('.', $domain); for($idx = 0; $idx < count($labels) -1; $idx ++){ // no null labels if(strlen($labels[$idx]) == 0) return false; // labels may not exceed 63 chars if(strlen($labels[$idx]) > 63) return false; // check that the label is valid if(! preg_match($labelpattern, $labels[$idx])) return false; } // check the TLD if(! preg_match($rootpattern, $labels[count($labels) - 1])) return false; // note, terminated domains with . to prevent // local domain wildcards from playing havoc. if($checkdomain) { if(! checkdnsrr($domain . '.', "MX")){ if(! checkdnsrr($domain . '.', "ANY")) return false; } } return true; } else return false; } } ?>