<?

        
/**
          * email2.php
          *
          * A more advanced regular expression to cover more cases.
          *
          * Dan Armendariz
          * David J. Malan
          * Computer Science S-75
          * Harvard Extension School
          */
                                                                                         

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Regex email example</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>

<body>

    <?
        
if(isset($_POST['email'])) {
            echo 
"<strong>$_POST[email]</strong> ";
            if(
preg_match("/.+@.+\.(edu|com|net)$/"$_POST['email']))
                echo 
"Validates!";
            else
                echo 
"Not valid!";
        }
            
    
?>    

    <form action="" method="post">
        <input type="text" name="email" />
        <input type="submit" />
    </form>

</body>
</html>