为什么我的电子邮件验证无效[关闭]

I would appreciate some help validating an email address in PHP. The format for the email that I need is firstname.lastname@mohawkcollege.TLD, .com, .ca, or .org being valid TLDs.

My function is:

function validateEmail($email)
{
    $regex = "/[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/";
    if (!preg_match($regex, $email))
    {
        return "<li>Email is in wrong format</li>"
    }
}

Use:

/[a-zA-Z0-9-_.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/

or

/[a-zA-Z0-9_\-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/

Put - after _ would make a confusion, so either escape it or put it before _