This PHP snippet (function) allows you to check if an email address from an educational institution.
<?php
/**
* @title Check if it is a valid and university email address.
*
* @param string $sEmail
* @return boolean
*/
function isUniversityEmail($sEmail)
{
return preg_match('/^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+edu$/i', $sEmail);
}
?>
Example of usage:
if (!isUniversityEmail('you@post.harvard.edu'))
exit('You must have a valid and .edu email address to register for an account.');
Good code! ;-)