Take a deeper look at your script's flow/logic, and think about what it does.
The email is only being validated if the "name" is empty. Meaning, if the user enters a name, the email won't be validated at all.
And on another note, there shouldn't be quotes around the $regex variable.