Harry M
Harry M

Reputation: 2088

using preg_match to check email domain

How can I modify the preg_match function below to allow all email addresses ending with harvard.edu email addresses, instead of only those with @college.harvard.edu?

if(!preg_match("/@college\.harvard\.edu$/", $_POST["username"]))
    {
        apologize("You must provide a Harvard email to register.");
    }  

Upvotes: 1

Views: 2104

Answers (1)

James McDonnell
James McDonnell

Reputation: 3710

if(!preg_match("/@.*harvard\.edu$/", $_POST["username"]))
{
    apologize("You must provide a Harvard email address to register.");
}

Upvotes: 6

Related Questions