Hello all,
I am having a hard time trying to figure out why I can't get my code to successfully check my email address. It seems I can plug in anything and it won't give me an error.

This is my code for that line:

<?php
session_start();
if((!empty($_POST['email'])
&& (preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email']) <50)))
{
$email=$_POST['email'];
$email=htmlspecialchars($email);
$_SESSION['email'] = $email;
}
else
{
$errors[]= 'You forgot to enter a valid E-mail Address!';
}

if (empty($errors))
{
header
("Location:http://www.thisnextpage.php");
exit();
}

if (!empty($errors) && is_array($errors))
{
echo '<h1>Error!</h1>
The following error(s) occured:<br/ >';
foreach ($errors as $msg)
{
echo " - $msg<br />\n";
}
}

?>

When I type in just letters and don't include @ it accepts it and moves me right along. It's supposed to stop me and tell me to enter a valid email address. Hmmmm...

Any help will be appreciated :)
~Amy

why are comparing the preg_match to "<50". preg_match returns true or false. it will return a matches array that you can get the count of if you are trying to make sure there are not over 50 email addresses in the field, which is probably not what you are trying to do.

just remove that and it should work. i didn't check out the rest of the code though, so I can't tell for sure.

Hi...
Why are u comparing this value with 50....
preg_match returns true of false...
If you are comparing with the strlength, then use different if for comparing the string length..

use the following if condition..
this will run...

if( !empty($_POST['email'])  && preg_match('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $_POST['email']) )

Oh, I see. I was trying to control how many characters were entered in the box. Silly me. Thanks everyone! It works now!
~Amy

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.