0015 | PHP Email Validation

บทความนี้อ้างอิง + คัดลอกมาจากเว็บไซต์ต่อไปนี้
Spoono.com – Spoono – PHP Tutorials – Email Validation

แบบว่ากำลังหาตัว validate email เพลินๆ ไปเจอตัวนี้มา ถูกใจครับ (ฮาๆ)
เอามาลง เผื่อเก็บไว้ใช้อีก

0000ff;">function 993300;">checkEmail(008080;">$email) {
0000ff;">if (ff0000;">eregi(ff00ff;">“^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]”, 008080;">$email)) {
0000ff;">return false;
}

0000ff;">list(008080;">$Username, 008080;">$Domain) = ff0000;">split(ff00ff;">“@”,008080;">$email);

0000ff;">if (ff0000;">getmxrr(008080;">$Domain, 008080;">$MXHost)) {
0000ff;">return true;
} 0000ff;">else {
0000ff;">if (ff0000;">fsockopen(008080;">$Domain, 993300;">25, 008080;">$errno, 008080;">$errstr, 993300;">7)) {
0000ff;">return true;
} 0000ff;">else {
0000ff;">return false;
}
}
}

ปล. ทำ syntax highlight แบบอัตโนมือนี่เหนื่อยนะเนี่ย

Tags: , ,

  • http://rtsp.us/ RTSP

    รุ้เลยว่าใช้ editplus

  • http://rtsp.us/ RTSP

    รุ้เลยว่าใช้ editplus

  • exboy

    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known

    Warning: fsockopen() [function.fsockopen]: unable to connect to :25 (Unknown error)

    ลองแล้วขึ้นแบบนี้ครับ

  • exboy

    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known

    Warning: fsockopen() [function.fsockopen]: unable to connect to :25 (Unknown error)

    ลองแล้วขึ้นแบบนี้ครับ

  • Unlocker

    function win_getmxrr($hostname, &$mxhosts, &$mxweight=false) {
        if (strtoupper(substr(PHP_OS, 0, 3)) != ‘WIN’) return;
        if (!is_array ($mxhosts) ) $mxhosts = array();
        if (empty($hostname)) return;
        $exec=’nslookup -type=MX ‘.escapeshellarg($hostname);
        @exec($exec, $output);
        if (empty($output)) return;
        $i=-1;
        foreach ($output as $line) {
            $i++;
            if (preg_match(“/^$hostnametMX preference = ([0-9]+), mail exchanger = (.+)$/i”, $line, $parts)) {
              $mxweight[$i] = trim($parts[1]);
              $mxhosts[$i] = trim($parts[2]);
            }
            if (preg_match(‘/responsible mail addr = (.+)$/i’, $line, $parts)) {
              $mxweight[$i] = $i;
              $mxhosts[$i] = trim($parts[1]);
            }
        }
        return ($i!=-1);
    }

    // Define
    if (!function_exists(‘getmxrr’)) {
        function getmxrr($hostname, &$mxhosts, &$mxweight=false) {
            return win_getmxrr($hostname, $mxhosts, $mxweight);
        }
    }

    function checkEmail($email)
    {
    if (eregi(“^[a-zA-Z0-9_]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$]”, $email)) {
    return false;
    }

    list($Username, $Domain) = split(“@”,$email);

    if (getmxrr($Domain, $MXHost)) {
    return true;
    } else {
    if (fsockopen($Domain, 25, $errno, $errstr, 7)) {
    return true;
    } else {
    return false;
    }
    }
    }แบบนี้ใช้ได้ทั้ง Windows และ Linux