Email validity check

Posted: April 16th, 2008 | Author: admin | Filed under: Developers |

PHP code:

<?php
function is_email($email) {
    $x = '\d\w!\#\$%&\'*+\-/=?\^_`{|}~';    //just for clarity
    return  count($email = explode('@', $email, 3)) == 2 &&
            strlen($email[0]) < 65 && strlen($email[1]) < 256 &&
            preg_match("#^[$x]+(\.?([$x]+\.)*[$x]+)?$#", $email[0]) &&
            preg_match('#^(([a-z0-9]+-*)?[a-z0-9]+\.)+[a-z]{2,6}.?$#', $email[1]);
}
?>
 



Leave a Reply