PHP Script: Require .edu email extension in registration

Discussion in 'PHP' started by worldman, Nov 30, 2010.

  1. #1
    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 :)
     
    worldman, Nov 30, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    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:
     
    MyVodaFone, Nov 30, 2010 IP
  3. underground-stockholm

    underground-stockholm Guest

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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).
     
    underground-stockholm, Dec 1, 2010 IP