0
        if(!$email_p) 
        {
            $forgot_error .= "Error - Enter your email address";
        }
        else if(preg_match( "/[a-zA-Z0-9-.+]+@[a-zA-Z0-9]+.[a-zA-Z]+/", $email_p) < 0)
        {
            $forgot_error .= "Invalid e-mail address";
        }





    i want to make sure email that user enter is right format. but for some reason it never goes in else if statment. can some one check if this is right?


preg_match( "/[a-zA-Z0-9-.+]+@[a-zA-Z0-9]+.[a-zA-Z]+/", $email_p < 0


    also what stuff is good idea to put after "A-Z and before @" ex: #$%^&*(}{"><?)_+= stuff like this

Edited by hwoarang69

4
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by Bob Hensley
4

@hwoarang69

i want to make sure email that user enter is right format. but for some reason it never goes in else if statment. can some one check if this is right?

You just want to see the if statement? Then try this:

if(!$email_p)
{
$forgot_error .= "Error - Enter your email address";
}
else if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email_p))
{
$forgot_error .= "Invalid e-mail address";
}

Edited by LastMitch: grammer

Votes + Comments
To Rectify what some retard did to LastMitch
0

i think so. do you mean this:

else if(filter_var($email_p, FILTER_VALIDATE_EMAIL))

i tried this but i was having the same problem.

also the key word "FILTER_VALIDATE_EMAIL" is in dark brown color in dreamwear. not sure if tht suposse to mean any thing,

Edited by hwoarang69

1
if(!$email_p)
{
$forgot_error .= "Error - Enter your email address";
}
else if (!filter_var($email_p, FILTER_VALIDATE_EMAIL))
{
$forgot_error .= "Invalid e-mail address";
}

What about the '!' before the filter_var?

1

Break down exactly what you're doing and see if you can spot the logic problem.

if ( ! $email_p) 
{
  $forgot_error .= 'Error - Enter your email address';
}
else if (filter_var ($email_p, FILTER_VALIDATE_EMAIL))
{
  $forgot_error .= "Invalid e-mail address";
}

Your first statement is checking to see if $email_p is not defined; if it isn't, you shoot off the error message.

The second statement is checking to see if $email_p is a valid email address (by format, anyways). If it is, you shoot off an error message.

Do you see the problem now? Your logic doesn't line up with what you're trying to accomplish.

else if ( ! filter_var ($email_p, FILTER_VALIDATE_EMAIL))

Or

else if ( FALSE === filter_var ($email_p, FILTER_VALIDATE_EMAIL))

Whichever style you prefer.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.