I am developing a user registration form and want to validate a user's email address. However,all the php docs I have read suggest the use of filter_var. My script validates a valid email as invalid. Please post a working script or perhaps guide me through my script. Hers is my script :
<?php
if(isset($_POST['email'])== true && empty($_POST['email'])false)
{
$email = $_POST['email'];
}
if(filter_var($email,FILTER_VALIDATE_EMAIL))
{
echo"valid email";
}
else
{
echo"invalid email";
}
?>
if(isset($_POST['email'])== true && empty($_POST['email'])false)
this should be
if(isset($_POST['email']) && !empty($_POST['email']) )
or as @jack you can use just
if (!empty($_POST['email']))
the empty() does implicit isset()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With