I have a form on my home page for people to subscribe to a mailing list, this works and the content of my email address field gets stored correctly within my sqlsrv database.
Now I am trying to add email validation so have copied a bit of code from my registration script but this doesn’t work and still allows me to just submit “test”.
The code is as follows:
I have added this function just under the database connection details:
[CODE]function isEmail($email){
return preg_match(‘/^S+@[wd.-]{2,}.[w]{2,6}$/iU’, $email) ? TRUE : FALSE;
}
I have then added the following in the process of what happens when submit is clicked:
[CODE]// Validate Email
if(!isEmail($data[’emailAD’])) {
$err[] = “ERROR – Invalid email address.”;
//header(“Location: index.php?msg=$err”);
//exit();
}
And finally, just under my subscribe box on the home page I have inserted the following to display the errors:
[CODE]<?php
if(!empty($err)) {
echo “<div class=”msg”>”;
foreach ($err as $e) {
echo “* $e <br>”;
}
echo “</div>”;
}
?>
Thanks