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

Recommended Answers

All 5 Replies

Member Avatar for LastMitch

@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";
}
commented: To Rectify what some retard did to LastMitch +0
Member Avatar for diafol

have a look at filter validations ffor pphp thhere's one for email

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,

Member Avatar for diafol
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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.