What I want to do is the following
I have a form with 8 fields,all of these fields are optional
but if one of the fields is filled in ie. the email address field
I want to validate the email address.
Hence I use this code
// Check for a email address
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",stripslashes(trim($_POST['email_address']))))
{
$e = escape_data($_POST['email_address']);
}
else
{
$e = FALSE;
echo '<p class = "validation">Please enter a valid email address</p>';
}
But what do I do if it is not filled in I don't want this code to happen so I do the following
if (isset($_POST['email_address']))
{
// Check for a email address
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",stripslashes(trim($_POST['email_address']))))
{
$e = escape_data($_POST['email_address']);
}
else
{
$e = FALSE;
echo '<p class = "validation">Please enter a valid email address</p>';
}
}
else
{
carry on as normal
}
but this doesn't work it keeps going into the vaidation code even if it is empty
I have also used
if (strlen($_POST['email_address']) > 0)
{
etc, etc
but that doen't work either
Please help
Regards
Graham
I have a form with 8 fields,all of these fields are optional
but if one of the fields is filled in ie. the email address field
I want to validate the email address.
Hence I use this code
// Check for a email address
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",stripslashes(trim($_POST['email_address']))))
{
$e = escape_data($_POST['email_address']);
}
else
{
$e = FALSE;
echo '<p class = "validation">Please enter a valid email address</p>';
}
But what do I do if it is not filled in I don't want this code to happen so I do the following
if (isset($_POST['email_address']))
{
// Check for a email address
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",stripslashes(trim($_POST['email_address']))))
{
$e = escape_data($_POST['email_address']);
}
else
{
$e = FALSE;
echo '<p class = "validation">Please enter a valid email address</p>';
}
}
else
{
carry on as normal
}
but this doesn't work it keeps going into the vaidation code even if it is empty
I have also used
if (strlen($_POST['email_address']) > 0)
{
etc, etc
but that doen't work either
Please help
Regards
Graham