0

I'm a still learning PHP and I'm programming a .php Registration webpage, and I want to make sure that the e-mail is valid (if the user doesn't type @ or . he will get a error message).

That's the e-mail part:

$Email = $_POST['email'];
$needle = '@';
$search = strpos($Email, $needle);

elseif ($search == FALSE)
            {
                echo "Your e-mail is not valid.";
            }

How can I make it with multiple letters instead of only @? I want to add the dot (.com) as well, I added it on $needle but it doesnt work. Thanks in advance.

Brandon
  • 16,382
  • 12
  • 55
  • 88

1 Answers1

0

Use filters they are way beter suited for this job:

if(!filter_var($Email, FILTER_VALIDATE_EMAIL))
 {
    echo "E-mail is not valid";
 }
Mouser
  • 13,132
  • 3
  • 28
  • 54