Domanda

Here is my code (from submit.php) that is throwing an error:

$email_from = $_POST['email']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

I know I need to use preg_match, but I don't know how to implement it. I've read the documentation, but I still don't get it. Thanks!

È stato utile?

Soluzione

$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
 if(preg_match($email_exp,$email_from) != 1) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}

Actually, it'is very simple and very similar with eregi.

Altri suggerimenti

remove this

  $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  eregi($email_exp,$email_from) 

and use

$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
preg_match($email_exp, $email_from)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top