I am creating a registration page for a college web application. I'm wondering if anyone knows a simple script that I could include in my authentication script to make sure the user registered with a .edu email address? Thanks in advance
Here's two examples //$email = "some.body@somedomain.edu"; $email = "some.body@somedomain.com"; if (stripos($email,".edu") !== false) { // echo "Valid e-mail address, processing..."; } else { echo "Please supply a valid .edu email address"; exit; } PHP: //$email = "some.body@somedomain.edu"; $email = "some.body@somedomain.com"; if (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.edu/", $email)) { die("Please supply a valid .edu email address"); }else{ // echo "Valid e-mail address, processing..."; } PHP:
Sorry, but these two examples could be bypassed with strings like "user@foo.edu.evildomain.com". Try something like: preg_match('%\.edu$%si', $addr) instead (untested).